home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / gfaxpert.lzh / GFAXPERT.DOC < prev    next >
Encoding:
Text File  |  1986-10-19  |  221.7 KB  |  5,746 lines

  1. 066010303050000132002006006010000
  2. 11
  3. 2- # -1
  4. F0110000001
  5. R   [.◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆...]0010
  6. 9[....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆..]1010
  7. ü
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21. 9[....◆....◆....◆....◆....◆....◆....◆..]3010
  22. YourSecond
  23. GFA-BASIC3.0
  24. Manual
  25.  
  26.  
  27.  
  28. 9[....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆..]1010
  29. SecondEdition
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. (c)HanKempen
  49. Coevorden,1990Ç
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. üEverythingyoualwayswantedtoknowabout
  61. GFA-Basic3.0,butwereafraidtoask
  62.  
  63. 9[:::::::::::::::::::::::::::::::::::::::◆::::◆::::◆::::◆::::◆::::◆::::◆::::◆:]1010
  64. üëCONTENTS
  65. ü
  66.           
  67. êINTRODUCTIONÇ..........................7ê
  68. Ç
  69. ê1.GENERALÇê
  70. ÇStart-up..............................9
  71. Application...........................9
  72. Monitor...............................10
  73. Break.................................10
  74. OperatingSystem......................10
  75. ê
  76. 2.THEEDITORÇê
  77. ÇAbbreviatedCommands..................12
  78. Syntax................................12
  79. FoldedProcedures.....................13
  80. Tab...................................13
  81. CutandPaste.........................13
  82. Load..................................13
  83. Save..................................14
  84. Llist.................................14
  85. Insert-mode...........................15
  86. Directmode...........................15
  87. DEFLIST...............................15
  88. SpecialCharacters....................16
  89.  
  90. ê3.VARIABLESÇê
  91. ÇVariableType.........................17
  92. DEFWRD................................17
  93. Boolean...............................17
  94. Integer...............................18
  95. FloatingPoint........................18
  96. VAR...................................18
  97. FUNCTION..............................19
  98. CLEAR.................................19
  99. ERASE.................................19
  100. DUMP..................................19
  101. TYPE..................................20
  102. READ..................................20
  103. SWAP..................................20
  104. TIME$.................................21
  105. TIMER.................................21
  106. DATE$.................................22
  107.  
  108. ê4.MEMORYÇ
  109. RAM...................................23
  110. INT{}.................................23
  111. RESERVE...............................23
  112. INLINE................................24
  113. MALLOC................................25
  114. ê
  115. ê5.SORTÇê
  116. ÇQSORTv.SSORT........................26
  117. QSORTofnumber-arrays................26
  118. QSORTofstring-arrays................26
  119. ê
  120. 6.OPERATORSandNUMERICALFUNCTIONSÇê
  121. Ç\.....................................29
  122. PREDandSUCC.........................29
  123. MOD...................................29
  124. BCLR..................................29
  125. BSET..................................30
  126. BCHG..................................30
  127. LOG...................................30
  128. SINQandCOSQ.........................30
  129. EQV...................................31
  130. CARDandSWAP.........................31
  131. MAX...................................31
  132. Correlation...........................31
  133. ê
  134. 7.STRINGSÇ
  135. INSTR.................................32
  136. LSETandRSET.........................32
  137. Parser................................32
  138. ê
  139. 8.KEYBOARDINPUTÇ
  140. INKEY$................................33
  141. INPUT.................................34
  142. INPUT$................................35
  143. LINEINPUT............................35
  144. KEYTEST...............................35
  145. KEYGET................................35
  146. KEYLOOK...............................36
  147. KEYPRESS..............................37
  148. KEYDEF................................37
  149. Keyboard..............................37
  150. Keyclick,KeyrepeatandCapsLock......38
  151. ê
  152. 9.SCREENOUTPUTÇ
  153. PRINT.................................40
  154. LOCATE................................41
  155. PRINTTAB.............................42
  156. Setscreen(XBIOS5)...................42
  157. Font..................................43
  158. ê
  159. 10.PRINTERÇê
  160. ÇPrinterready.........................45
  161. HARDCOPY..............................45
  162. Printer-commands......................47
  163. ê
  164. ê11.FILESÇ
  165. FloppyWriteTest.....................50
  166. StepRate.............................50
  167. RAM-disk..............................50
  168. DIR$()................................50
  169. DIRandFILES.........................51
  170. FSFIRSTandFSNEXT....................52
  171. EXIST.................................54
  172. LOF...................................54
  173. TOUCH.................................54
  174. NAME..................................54
  175. KILL..................................54
  176. FileCopy.............................55
  177. DiskFormat...........................55
  178. FileAllocationTable(FAT)...........58
  179. Sectors...............................59
  180. Bootsector............................61
  181. BLOAD.................................61
  182. INPandOUT...........................62
  183. INPUTandLINEINPUT..................62
  184. STOREandRECALL......................62
  185. FILESELECT............................63
  186.  
  187. ê12.MIDIÇê
  188. ÇINPMID$...............................67
  189. INP...................................67
  190. Midi-commands.........................67
  191. ê
  192. 13.MODEMÇ
  193. INPAUX$...............................70
  194. INP...................................70
  195. Rsconf(XBIOS15)......................70
  196. ê
  197. 14.MOUSEÇ
  198. Editor................................71
  199. Fileselector..........................71
  200. MOUSE.................................71
  201. SETMOUSE..............................71
  202. DEFMOUSE..............................72
  203. ê
  204. 15.JOYSTICKÇ
  205. STRIGandSTICK.......................74
  206. ê
  207. 16.SOUND
  208. ÇSOUNDandWAVE........................75
  209. Dosound(XBIOS32)....................75
  210. Samples...............................76
  211. Speech................................77
  212. Soundmachine..........................77
  213. ê
  214. ê17.PROGRAMDECISIONSÇê
  215. ÇIF...ENDIF..........................78
  216. SELECT................................78
  217. ê
  218. 18.PROGRAMLOOPS
  219. ÇCalculations..........................79
  220. FOR...NEXT..........................79
  221. Loops.................................80ê
  222.  
  223. 19.PROGRAMCONTROLÇ
  224. GOSUB.................................82
  225. ONBREAKGOSUB........................82
  226. ERROR.................................82
  227. EVERYandAFTER.......................82
  228. GOTO..................................82
  229. DELAY.................................83
  230. CHAIN.................................83
  231. EXEC..................................83
  232. ê
  233. 20.GRAPHICS
  234. ÇSETCOLORandVSETCOLOR................84
  235. Palette...............................84
  236. DEFMARK...............................87
  237. DEFFILL...............................87
  238. DEFLINE...............................89
  239. DEFTEXT...............................89
  240. GRAPHMODE.............................90
  241. PLOTandDRAW.........................91
  242. PCIRCLE...............................92
  243. CURVE.................................92
  244. TEXT..................................92
  245. SPRITE................................93
  246. VQT_EXTENT............................95
  247. Line-A................................95
  248. HLINE.................................96
  249. ACHARandATEXT.......................96
  250. GETandPUT...........................96
  251. Degas-Pictures........................97
  252. Neochrome-Pictures....................98
  253. VSYNC.................................98
  254. Scroll................................98
  255. ACLIP.................................99
  256. Blitter...............................99
  257.  
  258. ê21.EVENTSÇê
  259. ÇMENU()................................101
  260. ONMENUBUTTON........................101
  261. ONMENUIBOX..........................102
  262. ê
  263. ê22.PULLDOWNMENU
  264. ÇOPENW0...............................103
  265. Desk-submenu..........................103
  266. File-submenu..........................103
  267. ê
  268. 23.WINDOWSÇ
  269. GFA-windows...........................104
  270. CLOSEW................................104
  271. TITLEW................................105
  272. CLEARW................................105
  273.  
  274. ê24.AES-LIBRARYÇ
  275. ALERT.................................106
  276. SHEL_GETandSHEL_PUT.................106
  277.  
  278. ê25.GFAXPERT-FILESÇê
  279. ÇGFAXPERT.DOC..........................108
  280. GFAXPERT.LIB..........................108ê
  281. ÇINLINE................................108ê
  282. ÇSTANxxxx.LST..........................108
  283. START.................................112
  284. ásmallprintóÇ...........................113
  285.  
  286. êEPILOGUEÇ..............................114
  287.  
  288. êINDEXÇ.................................115ê
  289.  
  290.  
  291. 9[....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆....◆..]1010
  292. üëINTRODUCTION
  293. Ç
  294. ü
  295. ÇRightnowyouarereadingthesecondeditionofthetextGFAXPERT.DOC.
  296. ThistextisnotmeanttobeareplacementofyourGFA-manual.Onthe
  297. contrary,IassumeyouarealreadyfamiliarwiththeGFA-manualandnow
  298. wanttoknoweverythingaboutGFA-Basic3.0thatisnotdescribedproperly
  299. inthemanual.
  300.  
  301. Thistextisaboutthe(hidden)powerofGFA-Basic3.0.Youwillfind
  302. nothingaboutversion3.5,apartfromthissentence.Andthissentence,
  303. becauseIwouldliketomentionthatIdon'tunderstandwhyGFAlaunched
  304. version3.5.GFA-Basicisbecomingfartooexpensive.
  305.  
  306. Allremarksinthistext,especiallyaboutbugs,arebasedonGFA-Basic
  307. 3.07.Istillhopeversion3.08willbecomeavailable(hownaive...),
  308. otherwiseI'llhavetowaitforversion4.Notversion4.00ofcourse,
  309. becauseIknowtherewillbeatleast200bugsinthefirstrelease.
  310.  
  311. IwrotethistextbecauseIwasdisappointedbythecontentsofmostbooks
  312. aboutGFA-Basic3.0.Someauthorsusepageafterpagetodescribeaboring
  313. program.Othersdelvedeeplyintomenu's,windowsandRSC,butignorethe
  314. "regular"Basic-commands.Insteadofcomplaining,Idecidedtowritethe
  315. bookthatIwouldreallyliketoseemyself.Hereitis.Forgetallother
  316. booksaboutGFA-Basic,youneedonlytwothings:yourGFA-manualandthis
  317. text.Andtobehonest,perhapsagoodbookabouttheAES-library,because
  318. youwon'tfindmuchaboutthatsubjectinthistext.
  319.  
  320. InthistextyouwillfindquiteafewProcedures.MostProceduresthat
  321. arelisted(ormentioned)inthistextcanbefoundinoneoftheLST-
  322. filesinthefolderGFAXPERT.LIB.Downloadersshouldlookforthefile
  323. GFAXPRT2.ARC.
  324.  
  325. Istronglyadviseyoutoreadthechapter'GFAXPERT-FILES'thoroughly,
  326. beforeyoutrytousetheProcedure-libraryGFAXPERT.LIB.Especiallynote
  327. thefollowing:
  328.      (1)êwordÇ-variablesarethedefault
  329.      (2)acoupleofvariablesaredeclaredasêStandardGlobalsÇ
  330.      (3)someêStandardFunctionsÇaredefined
  331.      (4)afewêStandardProceduresÇarepresent
  332.      (5)theêStandardArrayÇcolor.index()isdeclared
  333. AProcedurecoulduseanyoftheStandardGlobals,Functions,Procedures
  334. ortheStandardArray.Iusuallymentionthisincomment-linesinthe
  335. Procedure.IfyouMergesuchaProcedureintoanexistingprogram,you
  336. willhavetoadaptyourprogramortheProcedure.
  337.  
  338. IstillbelieveinGFA-Basic3.0.AndIalsobelieveinsharingideas,
  339. Proceduresandprogramswithotherusers,startingwithyou.Ifyoufeel
  340. guiltyaboutreceivingallthesegoodiesfor(almost)nothing,youwill
  341. findafreeconsultinthechapter'EPILOGUE'.
  342.  
  343. ÇIcouldonlywritethistextbecausemanyGFA-userssharedtheir
  344. experiencewithothers.Idedicatethistexttothem.Specialthanksto
  345. everyonewhopointedoutbugs,mistakesandomissionsinthefirstedition
  346. ofGFAXPERT.DOC.Allmistakesinthesecondeditionaremadeby
  347.  
  348.  
  349. HanKempen
  350.  
  351.  
  352. üë1.GENERAL
  353. ü
  354.  
  355. Start-upÇ
  356.  
  357. ProgramsinanAUTO-folderareexecutedautomaticallyafterareset.The
  358. interpreterGFABASIC.PRGisaGEM-program,andcannotbestartedinthis
  359. way.WithTOS1.4youcaninstallaGEM-programasauto-booting.With
  360. olderTOS-versionsyoucoulduseaprogramlikeHEADSTRT.PRGinyourAUTO-
  361. foldertostartGFABASIC.PRGautomatically.Youcan'tstartaGFA-program
  362. thisway(Ithink).
  363.  
  364. Ifyouhavewrittena(compiled)programthatcanberuneitherfromthe
  365. AUTO-folderorfromthedesktop,youcandeterminewhichisthecase:
  366.      IFPEEK(&H2C+4)=0        !4thbyteofLine-Fvector
  367.      (...)                  !AUTO
  368.      ELSE
  369.      (...)                  !desktop
  370.      ENDIF
  371.  
  372. Thereareseveralwaysto(re)startyourcomputer.Theobviousoneisto
  373. switchtheSToff,waitafewseconds(15secondswitha1040ST!),and
  374. switchonagain.Thisiscalleda"cold"or"hard"reset.Yourcomputer
  375. suffersalittle,andittakessometime.Ifyouusethereset-buttonon
  376. yourST,youperforma"warm"or"soft"reset.Theoperatingsystem
  377. automaticallyperformsawarmresetifyouswitchbetweenLowandMedium
  378. resolutiononthedesktop.Ifyoususpectaprogramofchangingsystem
  379. variables,youshouldalwaysuseacoldreset.Afterawarmresetthe
  380. systemvariablesinlowmemoryareênotÇinitialisedagain.Garbagewill
  381. staythereandwillundoubtedlyleadtointerestingeffects.Youcan
  382. performbothawarmandacoldresetfromGFA-Basicwiththefollowing
  383. Procedures:
  384.      PROCEDURE coldstart
  385.        SLPOKE &H420,0
  386.      SLPOKE&H426,0         !probablynotnecessary
  387.        SLPOKE &H43A,0
  388.        ~XBIOS(38,L:LPEEK(4))
  389.      RETURN
  390.      '
  391.      PROCEDURE warmstart
  392.        ~XBIOS(38,L:LPEEK(4))
  393.      RETURN
  394.  
  395. Ifyouwouldliketobootfromyoursecond(external)driveB,try:
  396.      SLPOKE&H446,1      !bootfromdriveBafternextreset
  397.      @warmstart
  398.  
  399.  
  400. üApplicationÇ
  401.  
  402. ItisconvenienttoinstalltheextensionGFAasanapplicationfor
  403. GFABASIC.PRG.ClickonceonGFABASIC.PRGandchooseInstallApplication
  404. fromtheOptions-menu.TypeGFAasDocumentType,clickonOKandsavethe
  405. desktop.Ifyoudouble-clickaGFA-program(extension.GFA)fromthe
  406. Çdesktop,GFABASIC.PRGisautomaticallyloadedfirst.ChoosingInstall
  407. Applicationyouwillonlyseethemostrecentlyinstalledapplication.Use
  408. adisk-editortoexaminethefileDESKTOP.INFandyouwillfindall
  409. installedapplications(lookfor#G).Youcouldalsousethemethod
  410. describedintheparagraph'SHEL_GETandSHEL_PUT',ortheRECALL-method
  411. fromtheparagraph'STOREandRECALL'.
  412.  
  413.  
  414. üMonitorÇ
  415.  
  416. TheAtaricolourmonitorSC1224workswithaverticalfrequencyofeither
  417. 50Hzor60Hz:
  418.      SPOKE&HFF820A,254       !50Hz
  419.      SPOKE&HFF820A,252       !60Hz
  420. For60Hz,bit1oftheSyncModeRegisteriscleared.Don'tchangebit0,
  421. orthevideocontrollerchipwillnotusetheso-calledsyncpulses.After
  422. areset,theoperatingsystemdefaultsto50Hz.Thescreenisalittle
  423. largerthanat60Hz,butthescreenflickersslightly.Ifyouconnect
  424. yourSTtoaTVthroughamodulator,youshoulduse50Hz.Otherwiseyou
  425. areadvisedtouse60Hz.
  426.  
  427.  
  428. üBreakÇ
  429.  
  430. It'snoteasytofindintheGFA-manual:youcanstoparunningprogramby
  431. pressing<Control><LeftShift><Alternate>simultaneously.Butifyou're
  432. readingthistext,youknowthisalready.It'simpossibletointerrupta
  433. programduringDELAY!StudytheStandardProcedureBreakinoneofthe
  434. STANxxxx.LST-filestoseehowIreactaftera'Break'.
  435.  
  436.  
  437. üOperatingSystemÇ
  438.  
  439. IfyouprograminalanguagelikeGFA-Basic,youwon'tnoticemuchofthe
  440. actualworkhorseinsideyourST-computer:TheOperatingSystem(TOS).But
  441. evenGFA-BasicdoesnothaveaBasicequivalentforallTOS-functions,
  442. althoughyoucanusealmostallfunctionsfromGFA-Basic.
  443.  
  444. TOScanbedividedintwomainparts:(GEM)DOSandGEM.Thefirstisa
  445. collectionof"lowerlevel"routinesforcommunicationwithkeyboard,
  446. screen,printer,etc.InGFA-Basicyoucancalltheseroutineswiththe
  447. commandsBIOS,XBIOSandGEMDOS.TheGraphicsEnvironmentManager(GEM)
  448. consistsoftwocollectionsofroutines:theVDI(VirtualDevice
  449. Interface)andtheAES(ApplicationEnvironmentServices).TheVDItakes
  450. careofregulargraphicsandshouldhaveincludedGDOS.Atarididn't
  451. includeGDOSintheVDI,soyouhavetoloaditifyouneedit.MostVDI-
  452. functionshaveaBasicequivalentinGFA.TheAEStakescareofthe
  453. communicationwiththeuserthroughmenu,Alert-box,window,etc.Most
  454. AES-functionscanbeaccessedthroughtheAES-libraryinGFA-Basic3.0.
  455.  
  456. WithGEMDOS-function48(Sversion)youcanfindtheversionofyour
  457. GEMDOS.ForboththeoldTOSandtheBlitter-TOS&H1300(version0.19)is
  458. returned.TheFrenchTurbo-DOShasversion0.20andthenewRainbowTOSof
  459. 1988hasversion0.21.
  460. ÇAnotherwaytofindouttheversionofTOSusesthesystemheaderofTOS
  461. (notnecessarilylocatedinROM!):
  462.      adr%=LPEEK(&H4F2)
  463.      version$=HEX$(DPEEK(adr%+2))
  464. ThegoodoldROM-TOS(1986,actuallynotsogood)hasversion&H0100
  465. (1.0),theMega-STBlitter-TOS(1987)version&H0102(1.2).Andofcourse
  466. thenewTOS('RainbowTOS')hasversion1.4.Youcouldalsoexaminethe
  467. dateofyourTOS-version:
  468.      date$=HEX$(LPEEK(adr%+24))
  469. MyancientTOS1.0has'11201985'asthedate.
  470.  
  471.  
  472. üë2.THEEDITOR
  473. ü
  474.  
  475. AbbreviatedCommands
  476. Ç
  477. Theeditorrecognizesthefollowingabbreviations(notacompletelist):
  478.  
  479. ALINE     -ALI          FILESELECT-FILE         POLYMARK  -POLYM
  480. ARECT     -AR           FILL      -FI           PRINT     -Por?
  481. ARRAYFILL -ARR          FUNCTION  -FU           PROCEDURE-PRO
  482. ATEXT     -AT           GOSUB     -Gor@       PSET      -PS
  483. BMOVE     -B            GRAPHMODE -GRA          QUIT      -Q
  484. BOUNDARY  -BOU          HIDEM     -HI           REPEAT    -REP
  485. CASE      -CA           HLINE     -HL           RESTORE   -RES
  486. CIRCLE    -CI           IF        -I            RETURN    -RET
  487. CLOSE     -CL           INPUT     -INP          RSET      -RS
  488. COLOR     -C            LINE      -LI           SELECT    -S
  489. DATA      -D            LINEINPUT-LI           SETCOLOR  -SET
  490. DEFFILL   -DEFF         LOCAL     -LOC          SETMOUSE  -SETM
  491. DEFLINE   -DE           LOOP      -L            SGET      -SG
  492. DEFMARK   -DEFMA        LPRINT    -LPR          SHOWM     -SH
  493. DEFMOUSE  -DEFM         LSET      -LS           SWAP      -SW
  494. DEFTEXT   -DEFT         MID$(..)= -MI ..)=      TEXT      -T
  495. DELETE    -DEL          MOUSE     -MOU          UNTIL     - U
  496. DRAW      -DR           NEXT     -N            VOID      -V
  497. EDIT      -ED           OPEN      -O            VSYNC     -VS
  498. ELLIPSE   -ELL          PAUSE     -PA           WAVE      -WA
  499. ELSE      -E            PBOX      -PB           WEND      -WE
  500. ENDFUNC   -ENDF         PCIRCLE   -PC           WHILE     -W
  501. ENDIF     -EN           PELLIPSE  -PE           
  502. ENDSELECT -ENDS         PLOT      -PL           
  503. ERASE     -ERA          POLYFILL  -POLYF        
  504. EXITIF   -EX           POLYLINE  -POL          
  505.  
  506. Iftheabbreviatedcommandisfollowedbyanythingelse,youhaveto
  507. insertaspace(e.g.'C1'),exceptwith'@'and'?':
  508.      @proc1
  509.      Gproc1
  510.      '
  511.      ?"hello"
  512.      P"hello"
  513.  
  514.  
  515. üSyntax
  516. Ç
  517. Theparserchecksforcorrectsyntaxafteryoupress<Return>.Manytypo-
  518. bugsarepreventedthisway.Theonlydisadvantageisthattheparser
  519. recognizessomevariablesascommands.It'simpossibletousethefollo⑨
  520. wingnamesastheêfirstÇwordonaline:data_byte|,dirty$,double,
  521. printer$,file%,quit!.Thelastoneisnasty,becausetheparserchanges
  522. theline'quit!=FALSE'into'QUIT!=FALSE'withoutwarningforasyntax-
  523. error.IfyounowruntheprogramyouwillreturntothedesktopwhenQUIT
  524. isencountered.Ofcourseyouhavenotlostyourvaluableprogram,because
  525. youalwaysSavebeforeyouRun.Doyoureally?Iftheparserrefusesthe
  526. Çnameofavariable,youcanuseLET(e.g.'LETquit!=FALSE').Butyouwill
  527. havetochangethenameifitisalabel(e.g.thelabel'data1:'couldbe
  528. changedinto'1data:'or'd.ata1:').
  529.  
  530.  
  531. üFoldedProcedures
  532.  
  533. ÇIfyoupress<Control><Help>onaProcedure-line,allProceduresfollo⑨
  534. wingandincludingthecurrentonearefolded/unfolded.Youcanunfoldall
  535. ProceduresatoncebyputtingthecursoronthefirstProcedure-lineand
  536. pressing<Control><Help>.IsuggestyouleaveallProceduresinthe
  537. Procedure-LibraryGFAXPERT.LIBfolded,unlessyouwanttoexaminea
  538. Procedure.Theeditor-commands'Find'and'Replace'willskipfolded
  539. Procedures.NeverchangetheProcedure-lineofafoldedProcedure,always
  540. unfolditfirst.
  541.  
  542.  
  543. üTab
  544. Ç
  545. Ifyoupress<Tab>,thecursorjumpstothenexttab-position,without
  546. alteringthecurrentline.Ifyouuse<LeftShift><Tab>,thelineis
  547. filledwithspacesfromthecurrentcursor-positiontothenexttab-
  548. position.Pressing<RightShift><Tab>erasesallconsecutivespacesto
  549. theleftofthecurrentcursor-postition.Ifthecurrentcursor-position
  550. happenstobeaspace,thisspaceandallspacestotherightareerased
  551. aswell.
  552.  
  553.  
  554. üCutandPasteÇ
  555.  
  556. Ifyoupress<Control><P>,thecurrentlinefromthecursortotheendof
  557. thelineiscut,andsavedinaninternalbuffer.<Control><O>inserts
  558. thesavedlineatthecurrentcursor-position.Youcanusethismethodto
  559. "cutandpaste"apartofaline.Press<Control><P>,then<Control><O>
  560. torestoretheoriginalline.Movethecursortothedesiredpositionand
  561. press<Control><O>.Block-operationsareonlypossiblewithcomplete
  562. lines.
  563.  
  564.  
  565. üLoad
  566. Ç
  567. YoucanuseLoadonlywith*.GFA-files,notwithASCII-files(suchasthe
  568. *.LST-files).ST-BasicfilesareASCII-files,soyoucanMergethem.
  569.  
  570. MorerecentprogramsinGFA-Basic(from3.04)cannotbeloadedbyearlier
  571. interpreters(upto3.02).Ofcourseyoushouldhavethemostcurrent
  572. version(atleastversion3.07),butthefollowingmethodshouldalways
  573. work.Lengthentheprogramuntilyoucanloaditsuccessfully:
  574.      OPEN"A",#1,file$
  575.      PRINT#1,STRING$(1000,0)
  576.      CLOSE#1
  577.  
  578.  
  579. üSaveÇ
  580.  
  581. After'Save'(*.GFA-file)or'Save,A'(*.LST-file)withanexistingfile,
  582. theoldfileisrenamedwithaBAK-extension.Niceprecaution,butyou
  583. shoulddeletethose*.BAK-fileseverynowandthen.
  584.  
  585. Ifyoukillandsavefilesregularly,newfileswillbestoredina
  586. fragmentedway.Loadingafragmentedfiletakesmoretimethanloadinga
  587. filethatoccupiesconsecutivesectorsonthedisk.Youcancorrectthis
  588. asfollows.Firstmakeabackup-disk(yes,youshouldalreadyhaveone).
  589. CopyallfilestoaRAM-diskbyclickingonthedrive-iconanddraggingit
  590. tothewindowofthedestinationdrive.Youcan'tusedisk-copy(dragging
  591. drive-icontodrive-icon)becausethedestination-driveisaRAM-disk.
  592. Formatthesource-diskandcopyallfilesback(thisêmustÇbeafile-copy,
  593. notadisk-copy).Now,allfilesaresavedonconsecutivesectors.You
  594. couldspeedupthingsalittlebitmorebycopyingthemost-usedfiles
  595. first.Thedrive-headnowneedslesstimetoreachthesefiles.
  596.  
  597. Don'ttryto'Save,A'anexistingfiletoafulldisk.Ihavetriedit
  598. onceandlostboththeoriginalfile(shouldhavebecomea*.BAK-file)and
  599. ofcoursethesavedfile.Also,theeditor(orTOS)haderasedtheprogram
  600. frommemory...Thankyou.
  601.  
  602.  
  603. üLlistÇ
  604.  
  605. Therehasbeensomeconfusionaboutthefollowingpoint-commandsforthe
  606. printer:
  607.      .p-       -point-commandsarenotprinted
  608.      .p+       -point-commandsareprintedagain
  609.      .llxx     -line-width
  610.      .plxx     -page-length
  611.      .pa       -formfeed
  612. Sometimesthecommands'.cp'and'.nu'arementioned,butIdon'tknowhow
  613. tousethese.
  614.  
  615. Youcanonlyuseonepoint-commandinoneline.Iusethefollowinglines
  616. formyprinter(96characters/lineinElite-mode):
  617.      .p-
  618.      .n4
  619.      .lr3
  620.      .ll88
  621. SavethisasLLIST.LSTandMergeitafterthelastlineofaprogram
  622. beforechoosing'Llist'.Theactuallistingisthenprintedwith80
  623. characters/line,precededbytheline-numbers(4characters+space).If
  624. yourprogramislongerthan10000lines,youshoulduse'.n5',butinthat
  625. caseyouprobablydon'thavetimetoreadthis.Anicetouchisthe
  626. automaticexecutionofaformfeedafterprintingthelisting.
  627.  
  628. Ifthelistingcontainsspecialcharacters(ASCII-code<32or>126),
  629. someofthosecharactersmightbeinterpretedasprinter-commands.My
  630. printerswitchestocondensedprintingafterreceivingtheAtari-symbol.
  631. Installingtheproperprinter-driver(e.g.PTEPSON.PRG)willpreventthat.
  632. ÇButIneverinstallaprinter-driverbecausetherearesomeserious
  633. disadvantages.Readmoreaboutitintheparagraph'HARDCOPY'.
  634.  
  635. Youcanstoptheprintingprocessbypressingthe'Break'-combination
  636. <Control><LeftShift><Alternate>,unlessBreakhasbeendisabledwith
  637. 'ONBREAKCONT'.Yourprinterwillcontinueprintingthough,untilits
  638. input-bufferisempty,oruntilyouturntheprinteroff.
  639. ü
  640.  
  641. Insert-mode
  642. Ç
  643. Ifyoureturntotheeditor,you'llalwaysbeinInsert-mode,evenifyou
  644. lefttheeditorinOverwrite-mode.Bytheway,theeditorrestoresthe
  645. originalcolour-palette,soyouarenotbotheredbypalette-changesina
  646. program.IntheolddaysIwassometimescaughtbythedreadedphenomenon
  647. ofblackcharactersonablackbackground,butnowyoucanalwaysreadthe
  648. listingonyourscreen.
  649.  
  650. Bythesecondway,thereisonlyonethingIdon'tlikeabouttheGFA-
  651. editor.It'snoteasytomergeaProcedurefromaLST-filewiththe
  652. programyou'reworkingon.Savetheprogram,clearmemorywith'New',
  653. 'Merge'theLST-file,marktheProcedureasablock,savetheblock,
  654. 'Load'theoriginalprogram,findthecorrectlineand'Merge'thesaved
  655. block.AnewcommandNMerge(New+Merge)wouldmakethelifeofaGFA-
  656. programmeralittleeasier.AbetterideawouldbethecommandBMerge
  657. (Block-Merge).ThenIcouldchoosethiscommand,clipaProcedure-block,
  658. andtheblockwouldbeinsertedinthelistingautomatically.Areyou
  659. readingthis,Frank?Ifyouare,howaboutafunctionforchangingupper
  660. caseintolowercase.IntheGFA-EDITORISOMETIMES(oops)forgetI
  661. pressedCapsLock.Andhowaboutafunctiontoclearalinefromthecursor
  662. tothenextspace-character.And...
  663.  
  664.  
  665. üDirectModeÇ
  666.  
  667. EntertheDirectModebypressing<Esc>or<Shift><F9>intheeditor.
  668.  
  669. InDirectModeyoucanrestorethepreviouslyusedlinewith<Undo>.With
  670. <Uparrow>and<Downarrow>youcanevenrecallupto8ofthelastused
  671. lines.Press<Insert>toswitchbetweenInsert-modeandOverwrite-mode.As
  672. usual<Esc>clearstheline,butifyoupress<Esc>onanemptyline,you
  673. willreturntotheeditorimmediately.Youcanalsoreturntotheeditor
  674. with<Control><Shift><Alternate>,evenwithoutfirstclearingthe
  675. command-line.YoucancallProceduresinyourprogramfromtheDirectMode
  676. (e.g.'@show').Ifyou(temporarily)mergesomespecialProcedureswith
  677. theprogramyouaredeveloping,youcouldusetheDirectModeasaCommand
  678. LineInterpreter.
  679.  
  680.  
  681. üDEFLISTÇ
  682.  
  683. Thecommand'DEFLISTn'onlyworksinDirectMode,notinaprogram.You
  684. canalsochoose'Deflist'fromthedrop-downmenu,afterclickingonthe
  685. Atari-symbol.
  686. üSpecialCharacters
  687.  
  688. ÇYoucanentercharacterswithASCII-codeüÇ32-126üÇdirectlyfromthekey⑨
  689. board.ThesecharactersareusuallycalledASCII-characters.Thecodes
  690. 0-31and127areusedascontrol-codes,butadditionallyspecialcharac⑨
  691. tershavebeenassignedtothesecodes.Thecharacterswithcode128-255
  692. aresometimescalled"extendedASCII-characters"andarepartlyidentical
  693. totheIBM-characterswiththesamecodes.Ilooselyusetheexpression
  694. "ASCII-code"forallcodes0-255.
  695. Youcanentercharacterswithcode0-31or127-255bypressing<Alternate>
  696. andthenenteringthecharactercode.Releasethe<Alternate>-keyandthe
  697. characterappearsonyourscreen.E.g.,youcouldentertheEscape-
  698. characterbyholding<Alternate>downandpressing<2>and<7>.Thisis
  699. muchfasterthanenteringCHR$(27),butLlistingafilewithEscape-
  700. charactersisprobablynotagoodidea(lessimportant,1stWordPlus
  701. couldgetconfusedtoo).LlistingCHR$(27)doesn'tbotheryourprinterat
  702. all.It'snotpossibletoenterCHR$(10)orCHR$(13)withthe'Alternate'-
  703. way.Youcanenterthefirstbypressing<Control><A>andthen<1><0>
  704. <Return>.Forcode13youhavetouseCHR$(13).
  705.  
  706. Neverusecode4(EOT,visibleasleftarrow)inaLST-file.IfyouMerge
  707. aLST-file,theGFA-editorthinkstheendofthefileisreachedatthat
  708. point(&H04)andrefusestoloadanythingfollowingthiscode!
  709.  
  710.  
  711. üë3.VARIABLES
  712. Ç
  713.  
  714. üVariable-typeÇ
  715.  
  716. InGFA-Basicweusetheexpressions'Byte','Word'and'Integer'forthe
  717. threeinteger-variables.Becauseallthreeareintegers,theexpression
  718. 'Integer'forthe4-byteinteger-variableissligthlyconfusing.Inother
  719. languagesthisvariableiscalled'Longword'orsimply'Long'.Anaddress
  720. inRAMshouldalwaysbea4-byteinteger.
  721.  
  722. ü
  723. DEFWRDÇ
  724.  
  725. Iprefertodeclareword-variablesasthedefault(forvariableswithout
  726. postfix)with:DEFWRD"a-z"
  727.  
  728. Irecommendtheuseofword-variables(2bytes)fortworeasons.In
  729. calculations,theuseofthespecialinteger-operators(ADD,SUB,INC,
  730. etc.)speedstheprogramupconsiderably.Ifyouinsistonusingthe
  731. regularoperators(+,-,etc.)youshouldusefloatingpointvariables
  732. instead.Usingtheregularoperators,theinterpreterhastoconvert
  733. integer-variablestofloatingpoint,doesthecalculationandconvertsthe
  734. resultbacktointegeragain.That'swhya#*b#iscalculatedfasterthan
  735. a&*b&.ButMUL(a&,b&)ismuchfasterthana#*b#.Ittakessometimeto
  736. recognizewhatanexpressionlikeDIV(a,MUL(ADD(a,b),SUB(b,c)))means.I
  737. suggestyouusetheregularoperatorsifthecalculation-timeisnot
  738. critical.Inloops,thegainincalculationtimereallycounts,soyou
  739. shouldusetheinteger-operators.ThatwayyouwilllearnPolishtoo.The
  740. secondreasonforusingword-variablesis,thatinacompiledprogram
  741. calculationswithword-integersareusuallythefastest.
  742.  
  743. IMPORTANT:ifanumber-variablehasnopostfixinthistext,youshould
  744. assumeit'saêwordÇ-variable.I'llusethepostfix|,%or#where
  745. appropriate.Pleasenotethattheinterpreterassumesanumber-variable
  746. withoutpostfixisafloatingpointvariable,unlessyouuseDEFWRD"a-z".
  747.  
  748.  
  749. üBooleanÇ
  750.  
  751. Thefollowingfivelines:
  752.      IFnumber>0
  753.      test!=TRUE
  754.      ELSE
  755.      test!=FALSE
  756.      ENDIF
  757. canbeshortenedtojustoneline:
  758.      test!=(number>0)
  759. Thisworks,becausethe'>'-operatorreturnsTRUEorFALSE(actually-1
  760. or0).
  761.  
  762. ÇAnotherlittletrick:
  763.      IFi=1
  764.      n=n*2
  765.      ELSEIFi=2
  766.      n=n*5
  767.      ELSE
  768.      n=0
  769.      ENDIF
  770. Thiscouldbeshortenedto:
  771.      n=n*-2*(i=1)üÇ+n*-5*(i=2)
  772. Theexampleisridiculous,buttheprincipleinvolvedcouldbeuseful.The
  773. expressions'i=1'and'i=2'areeither0(FALSE)or-1(TRUE).
  774.  
  775. Itisnotnecessarytousesomethinglike:
  776.      IFflag!=TRUE
  777.      (...)
  778.      ENDIF
  779. Youcansimplyuse:
  780.      IFflag!
  781.      (...)
  782.      ENDIF
  783.  
  784.  
  785. üIntegerÇ
  786.  
  787. Youcan'tassign2^31toa4-byteinteger-variable.Althoughaninteger
  788. contains32bits,youcan'tusebit31.Thisbitisaflagforanegative
  789. integer.Thelargestpositivenumberyoucanassigntoaninteger-variable
  790. istherefore2^31-1(2147483647).Icouldhavewrittenananalogue
  791. paragraphaboutthe2-byteword-variables,butIdidn't.
  792. ü
  793.  
  794. FloatingPoint
  795. Ç
  796. Therangeoffloatingpointvariables(postfix#)is:
  797.      -1.0E1000<x#<1.0E1000
  798. LargerorsmallernumbersêcanÇbeusedincalculations,butnotprinted,
  799. becausetheexponentmaycontainnotmorethan3digits(1.0E1000is
  800. displayedas1.0E;00).
  801.  
  802.  
  803. üVAR
  804. Ç
  805. IfyoucallaProcedureanduseVAR(callbyreference),êallÇvariables
  806. and/orarraysafterVARarecalledbyreference.Anexampletoclarify
  807. this:
  808.      @test(10,5,number%,array%())
  809.      (...)
  810.      PROCEDUREtest(a,b,VARx%,y%())
  811.        'nowa=10andb=5(callbyvalue)
  812.        'number%andarray%()cannowbeusedasx%andy%()
  813.        x%=a+b                 !globalvariablenumber%isnow15
  814.        ARRAYFILLy%(),1       !allelementsofarray%()arenow1
  815.      RETURN
  816. ÇInprehistoricdaysyoucouldhaveusedSWAP,butVARmakeslifeeasier:
  817.      @test(*a%())
  818.      (...)
  819.      PROCEDUREtest(ptr%)
  820.        SWAP*ptr%,x%()        !arraya%()temporarilyrenamedasx%()
  821.        (...)                  !dosomethingwiththearray
  822.        SWAP*ptr%,x%()        !restorepointerbeforeleavingProcedure
  823.      RETURN
  824.  
  825.  
  826. üFUNCTIONÇ
  827.  
  828. YoucanonlyleaveaFUNCTIONbyRETURNingavalueorastring.This
  829. value/stringisusuallyassignedtoavariable.IftheFUNCTIONreturnsa
  830. string,thefunction-namehastoendwith'$':
  831.      FUNCTIONtest
  832.      RETURN126
  833.      ENDFUNC
  834.      '
  835.      FUNCTIONtest$
  836.      RETURN"thisisastring"
  837.      ENDFUNC
  838. ü
  839.  
  840. CLEARÇ
  841.  
  842. BecauseCLEARisautomaticallyexecutedwhenyourunaprogram,it'snot
  843. necessarytostartyouprogramwiththiscommand.
  844.  
  845. ü
  846. ERASEÇ
  847.  
  848. It'simpossibletoreDIMensionanexistingarray.YoufirsthavetoERASE
  849. theexistingarrayandthenyoucanDIMensionanewarray.Itisnot
  850. necessarytotestfortheexistenceofanarraywithDIM?()beforeyouuse
  851. ERASE.Inotherwords,youcanuseERASEevenifthearraydoesn'texist:
  852.      ERASEarray$()      !justincasethisarrayalreadyexists
  853.      DIMarray$(200)     
  854.  
  855. AfterERASEinganarray,GFArearrangestheremainingarrays.Allarrays
  856. thathavebeenDIMensionedafterthedeletedarrayaremovedinorderto
  857. fillthegapofthedeletedarray.ThisisimportantifyouuseV:array(0)
  858. inyourprogram(readtheparagraph'RESERVE').
  859.  
  860.  
  861. üDUMPÇ
  862.  
  863. Examineallvariablesinyourprogrambytyping'DUMP'inDirectMode.
  864. Press<CapsLock>toslowdownthescrolling-speed,orpresstheright
  865. <Shift>-keytotemporarilystopthescrolling.TheProcedureDebugenables
  866. youtouseDUMPduringdebugging.Thisisthebestwaytodiscoverthose
  867. nastytypo-bugsinavariable-name.You'llprobablybesurprisedtosee
  868. thenamesofdeletedvariablesaswell.Also,anyvariable-nameyouused
  869. inDirectModeappears.êAllÇthesenamesareSAVEdwiththeprogram!Delete
  870. Çallunwantednamesasfollows(aRAM-diskwouldbeconvenient):
  871.      -Loadthefile
  872.      -Save,A(press<Return>inFileselector)
  873.      -New
  874.      -Merge(press<Return>again)
  875.      -Save(press<Return>oncemore)
  876. Thefilecouldbemuchshorterafterthisoperation.
  877.  
  878.  
  879. üTYPE
  880.  
  881. ÇThecommandTYPEdoesnotseemtoworkproperlyifyouuselocal
  882. variables.Idon'tknowwhat'swrong.
  883.  
  884.  
  885. üREADÇ
  886.  
  887. Asarule,IalwaysRESTOREtheappropriatelabelbeforeREADingDATA-
  888. lines.ThatwayIcanuseDATA-linesinProcedures:
  889.      PROCEDUREread.data
  890.      RESTOREthese.data
  891.      (...)                  !READtheDATAhere
  892.      these.data:
  893.      DATA1,2,3,4
  894.      RETURN
  895.  
  896.  
  897. üSWAPÇ
  898.  
  899. The52cardsinbridge(oranothercard-game)canberepresentedbya
  900. byte-array.Filltheelements1-52ofthearraywiththevalue1-52.The
  901. values1-13wouldrepresenttheClub-cards(2,3,4,...,Q,K,A),values
  902. 14-26theDiamonds,values27-39theHeartsandvalues40-52theSpades.
  903. ShufflingthecardscannowbesimulatedwiththeProcedureShuffle:
  904.      DIMdeck|(52)
  905.      FORi=1TO52       !ignoreindex0
  906.      deck|(i)=i
  907.      NEXTi
  908.      @shuffle(deck|())
  909.      (...)
  910.      PROCEDUREshuffle(VARproc|())
  911.      LOCALi,j
  912.      FORi=DIM?(proc|())-1DOWNTO2
  913.      j=RAND(i)+1
  914.      SWAPproc|(j),proc|(i)
  915.      NEXTi
  916.      RETURN
  917.  
  918.  
  919. üTIME$Ç
  920.  
  921. YoucanuseTIME$toprintthecurrenttimeonthescreen.Inthe
  922. ProcedureTimeyou'llfindawaytoprintthetimeeverysecond,although
  923. TIME$isupdatedeveryêtwoÇseconds:
  924.      PROCEDURE time
  925.        ' *** activate with : EVERY 200 GOSUB time
  926.        ' *** global :  TIMER$
  927.        LOCAL t$
  928.        t$=TIME$
  929.        IF t$=timer$
  930.          MID$(timer$,8)=SUCC(RIGHT$(timer$))
  931.        ELSE
  932.          timer$=t$
  933.        ENDIF
  934.        PRINT AT(1,1);timer$
  935.      RETURN
  936.  
  937.  
  938. üTIMERÇ
  939.  
  940. Ifyouneedastopwatch,youcanusethefollowingProcedures:
  941.      PROCEDURE stopwatch
  942.        ' *** global :  STOP.SECONDS#  STOP.H  STOP.M  STOP.S  WATCH.ON!
  943.        LOCAL s#
  944.        IF watch.on!
  945.          stop.watch#=TIMER
  946.          stop.seconds#=(stop.watch#-start.watch#)/200
  947.          stop.h=stop.seconds#/3600
  948.          s#=stop.seconds#-stop.h*3600
  949.          stop.m=s#/60
  950.          stop.s=s#-stop.m*60
  951.          watch.on!=FALSE
  952.        ELSE
  953.          watch.on!=TRUE
  954.          start.watch#=TIMER
  955.        ENDIF
  956.      RETURN
  957.      ' 
  958.      PROCEDURE print.stopwatch
  959.        IF stop.h>0
  960.          PRINT stop.h;" h ";stop.m;" m";
  961.        ELSE
  962.          IF stop.m>0
  963.            PRINT stop.m;" m ";stop.s;" s";
  964.          ELSE
  965.            IF stop.seconds#>=10
  966.              PRINT USING "##.# s",stop.seconds#;
  967.            ELSE
  968.              PRINT USING "#.## s",stop.seconds#;
  969.            ENDIF
  970.          ENDIF
  971.        ENDIF
  972.      RETURN
  973. ÇYoustartthestopwatchbycallingtheProcedureStopwatch.Callingthis
  974. Procedureagainwillstopthestopwatch.ThenyoucanPRINTtheelapsed
  975. timeatthecurrentcursor-positionwiththeProcedurePrint.stopwatch,or
  976. youcoulduseoneoftheGlobalVariablesfromtheProcedureStopwatchto
  977. dosomethingelse.
  978.  
  979.  
  980. üDATE$
  981. Ç
  982. FindthedayoftheweekwiththeProcedureDay.of.week:
  983.      PROCEDURE day.of.week(day.date$,VAR day$)
  984.        LOCAL day,mp,month,year,m,h,w,week$,n
  985.        day=VAL(LEFT$(day.date$,2))
  986.        mp=INSTR(day.date$,".")
  987.        month=VAL(MID$(day.date$,mp+1,2))
  988.        year=VAL(RIGHT$(day.date$,4))
  989.        IF month<=2
  990.          m=10+month
  991.          year=year-1
  992.        ELSE
  993.          m=month-2
  994.        ENDIF
  995.        h=year/100
  996.        y=year-100*h
  997.        w=(TRUNC(2.6*m-0.2)+day+y+TRUNC(y/4)+TRUNC(h/4)-2*h) MOD 7
  998.        RESTORE weekdays
  999.        FOR n=0 TO w
  1000.          READ day$
  1001.        NEXT n
  1002.        '
  1003.        weekdays:
  1004.        DATA Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
  1005.      RETURN
  1006. ThisProcedureusesZeller'sCongruencetodeterminethedayoftheweek.
  1007.  
  1008.  
  1009. üë4.MEMORY
  1010. Ç
  1011.  
  1012. üRAMÇ
  1013.  
  1014. Anoverviewofthememoryofmy1040ST(startatthebottom):
  1015.                     êaddressÇ
  1016.                     &HFFFFFtopofmemoryof1040ST(1024K)
  1017.                     &HFFD00   767unused(?)bytes
  1018.        XBIOS(2)=&HF8000screenmemory(32000bytes)
  1019.        HIMEM=&HF400016384unusedbytes(MALLOC(-1))
  1020.                     &H.....freememory(lengthFRE(0)bytes)
  1021.                     &H388EAprogram+variables(lengthvaries)
  1022.                     &H10C2EGFA-Basic3.07interpreter
  1023.      BASEPAGE=&H10B2EBasepageGFA-Basic(256bytes)
  1024.                     &HA100startofavailableRAM
  1025.                     &H6100globalAES-variables
  1026.                     &H29B4globalBIOS-andGEMDOS-variables
  1027. L~A=&H293ALineAvariables
  1028.                     &H93AlocalBIOS-variables+BIOS-stack
  1029.                     &H400BIOSsystem-variables
  1030.                     &H0exceptionvectors
  1031.  
  1032. TheBIOSsystem-variables(&H400-&H4FF)are"castinconcrete"byAtari.
  1033. Other(undocumented)variablesinRAMshouldbeavoided.
  1034.  
  1035.  
  1036. üINT{}Ç
  1037.  
  1038. YoucanuseeitherINT{adr%}orWORD{adr%}.Asyouknow,w=WORD{adr%}is
  1039. fasterthanw=DPEEK(adr%),butyoucan'tuseWORD{}andtheotherrelated
  1040. commandsinsupervisormode.Thismeansyoucan'taccessmemorybelow
  1041. address&H800.OfcourseyoucanPEEK/DPEEK/LPEEKeverywhere(DPEEKand
  1042. LPEEKonevenaddressesonly),andyoucanuseSPOKE/SDPOKE/SLPOKEto
  1043. writeinsupervisormode.
  1044.  
  1045.  
  1046. üRESERVEÇ
  1047.  
  1048. ThecommandRESERVEcanbeusedinthreedifferentways:
  1049.      RESERVEn%:reserven%bytesforGFA-Basic,releaseRAMuptoHIMEM
  1050.      RESERVE-n%:reservelastn%bytesofRAMuptoHIMEM
  1051.      RESERVE:restoretooriginal
  1052. Thesecondcommandismyfavourite.YouêmustÇuseamultipleof256with
  1053. RESERVE.After'RESERVE-400',only256bytesarereleasedtoGEMDOS.In
  1054. thiscaseyouwouldhavetouse'RESERVE-512',althoughyouneedonly400
  1055. bytes!UsetheFunctionMultipleifarithmeticisnotyourstrongest
  1056. point :
  1057.      RESERVE-@multiple(n%,256)
  1058. Use'RESERVE-n%'onlyonceinyourprogram.IfyouRESERVEmemorya
  1059. secondtimewith'RESERVE-m%',GFAreleasesm%bytes,ênotÇn%+m%.
  1060.  
  1061. ÇThecommandRESERVE(restore)doesnotalwaysfunctionproperly.Especial⑨
  1062. lyafterEXEC3it'softenimpossibletorestorethememory.Isuspect
  1063. thishassomethingtodowiththeuseofthemalloc-functionbythe
  1064. operatingsystem.Youcouldtrythefollowing:
  1065.      RESERVE-n%         !reserveasmuchasneeded(multipleof256)
  1066.      base%=EXEC(3,...)   !load,butdon'tstart
  1067.      (...)
  1068.      ~MFREE(HIMEM)       !memoryaboveGFA-Basic
  1069.      ~MFREE(base%)       !memoryfromBasepageofloadedprogram
  1070.      RESERVE             !hopeitworksnow
  1071. Don'tbesurprisedbyhang-upsorbombsafterthisoperation...
  1072.  
  1073. Thereareseveralwaystoreserveapartofmemoryforspecialpurposes
  1074. suchasmusic,picturesorotherprograms.E.g.,youcoulduseastring-
  1075. variabletostoreacompletescreenoraGET-picture.Don'tusestringsif
  1076. garbagecollectionisaseriousrisk.Ifalargearrayisdeclared,the
  1077. interpretersometimesmovesthestringsinmemorytocreatespaceforthe
  1078. newarray.Ifyouassignanewstringtoanexistingstring-variable,the
  1079. oldstringisnoterased.Duringgarbagecollectionallunusedstringsare
  1080. deletedandtheactivestringsarerearranged.Thismeanstheaddressofa
  1081. string(accessedthroughVARPTRorV:)isnotfixed.That'snotimportant
  1082. foraGET-picture,because'PUTx,y,pic$'stillworksallright.Butif
  1083. youswapscreenswith~XBIOS(5,L:adr%,-1,-1),orcallaroutinewith
  1084. ~C:adr%(...),garbagecollectionwillbefatal.Onesolutionisnottouse
  1085. avariablefortheaddress,buttouseVARPTRorV:.Adifferentapproach
  1086. wouldbetheuseofabyte-array:
  1087.      OPEN"I",#1,file$
  1088.      LETbytes%=LOF(#1)            !howmuchspaceisneeded?
  1089.      CLOSE#1
  1090.      DIMassembler|(bytes%-1)!createspaceforassembler-routine
  1091.      adr%=V:assembler|(0)        
  1092.      BLOADfile$,adr%              !loadtheroutine
  1093. Youcanusethevariableadr%safely,becauseagarbagecollectionhasno
  1094. influenceonarrays.However,afterERASEinganarray,allarraysthat
  1095. havebeenDIMensionedafterthedeletedarrayaremovedinmemory.Sothe
  1096. array-methodisnotreliableeither,unlessyouarecertainthatERASE
  1097. willnotbeusedafteryouhavedeterminedtheaddressofthebyte-array.
  1098. Anothersolutionwouldbetodeclarethebyte-arrayearlyinyourprogram,
  1099. soitwillnotbemovedafterERASE.Theonlycompletesafewayistheuse
  1100. ofINLINEorMALLOC.
  1101.  
  1102.  
  1103. üINLINEÇ
  1104.  
  1105. UseD(=DUMP)todumpanInline-fileinHex-codetotheprinter.
  1106.  
  1107. Don'tuse'Save,A',becauseyouwilllosetheInline-code.Youcan'tuse
  1108. INLINEinLST-files.IfyouwouldliketouseINLINEincombinationwitha
  1109. LST-fileyoucouldproceedasfollows.First,createanINLINE-folderin
  1110. themaindirectoryandSAVEtheInline-codeasafile(extensionINL)in
  1111. thisfolder.MergetheLST-fileinyourprogramandloadtheInline-code
  1112. intheINLINE-line.Theprogramshouldbesavedwith'Save'.
  1113.  
  1114. ÇTheonlylimitationwithINLINEisthemaximumlengthof32746bytes.If
  1115. youneedmorespace,youhavetouseMALLOC.
  1116.  
  1117. IfyouchangethelengthofanexistingINLINE-line,theeditorsometimes
  1118. erasesafewlinesfromyourprogram.It'ssafertocompletelydeletethe
  1119. oldINLINE-lineandthenenterthenewINLINE-line.
  1120.  
  1121.  
  1122. üMALLOCÇ
  1123.  
  1124. ThisishowyoucoulduseMALLOC:
  1125.      unused%=MALLOC(-1)  !"unused"memoryaboveHIMEM(usedbyGEM)
  1126.      RESERVE-n%         !releaselastn%bytestoGEMDOS
  1127.      max%=MALLOC(-1)
  1128.      IFmax%<>0
  1129.      adr%=MALLOC(max%-unused%) !n%bytesnowavailabletoGFA-Basic
  1130.      ELSE
  1131.      'error
  1132.      ENDIF
  1133.      (...)               !dosomethinginteresting
  1134.      ~MFREE(adr%)        !givebacktoGEMDOS...
  1135.      RESERVE             !andbacktoGFA-Basic
  1136. Atarirecommendsyouleaveatleast8KtoGEM,soyoucan'tgowrongif
  1137. youleave16384bytestoGEM(seeparagraph'RAM').
  1138.  
  1139. DoênotÇuseMALLOCtoallocatealotofsmallmemory-blocks,asGEMDOSwill
  1140. getconfused.Thisproblemisrelatedtothe"40-folderlimit",because
  1141. MALLOCusesthesamebufferthatisusedtostoreinformationabouta
  1142. folder(seeparagraph'FILESELECT').Allocateonelargeareaandsplitit
  1143. upinasmanypartsasyouneed.AlsoconsidertheuseofINLINE,strings
  1144. orbyte-arraysinsteadofusingMALLOC(readtheparagraph'RESERVE').Do
  1145. notuseMALLOCinanaccessory,ortheallocatedmemorymaybelostifthe
  1146. userchangestheresolution.
  1147.  
  1148. MALLOC(-1)returnsthesizeoftheêlargestÇavailablememory-block.Expect
  1149. problemsifanotherprogramhasallocatedacoupleofseparatememory-
  1150. blockstoGEMDOS.InthatcaseyouwouldhavetouseMALLOC(-1)again,
  1151. untilareturnedvalueof'0'indicatestherearenomorememory-blocks
  1152. available.
  1153.  
  1154.  
  1155. üë5.SORT
  1156. Ç
  1157.  
  1158. üQSORTÇüv.SSORTÇ
  1159.  
  1160. QSORTisfasterthanSSORT,unlessthearrayisalmostsortedalready.I
  1161. understandQSORTusestherecursiveQuick-sortmethod,soyouneedmore
  1162. memorythanwithSSORT(iterativeShell-sort).Sort-freakscanstudythe
  1163. ProceduresQuick.sort.intandShell.sort.inttoseehowtheQuick-sortand
  1164. Shell-sortcanbeimplementedwithordinaryGFA-Basiccommands(likethat
  1165. dance:Quick,Shell,slow).
  1166.  
  1167.  
  1168. üQSORTofnumber-arrays
  1169.  
  1170. ÇNumber-arrayscanbeQSORTedinthreedifferentways:
  1171.      QSORTx%()          -sortsarray;alsowithx|(),x&()orx#()
  1172.      QSORTx%(),n        -sortselements0throughn-1
  1173.      QSORTx%(),n,y%()   -elementsofy%()areswappedtoo
  1174. Inallcasesx%(-1)resultsinsortingindecreasingorder.
  1175.  
  1176. Thethirdmethodisinterestingifyouneedasortedoutput,butdon't
  1177. wanttochangetheoriginalarray.Youcanaccomplishthisasfollows:
  1178.      -copyx%()totemporaryarraytemp%()
  1179.      -determineindexoflastelement:last=DIM?(temp%())-1
  1180.      -createindexarray:DIMindex%(last)
  1181.      -fillindex-arraywithindex0throughlast
  1182.      -sortarray:QSORTtemp%(),last+1,index%()
  1183.      -ERASEtemp%()
  1184. Theindex-arrayêmustÇbeaninteger-array(postfix%).Also,thenumberof
  1185. elementsisênotÇoptionalifyousortwithanindex-array.Youcannow
  1186. printthenumbersinarrayx%()inincreasingorder:
  1187.      FORi=0TOlast
  1188.        PRINTx%(index%(i))
  1189.      NEXTi
  1190.  
  1191. IhaveneverseenthecorrectsyntaxforQSORTinprint,sohereitis:
  1192.      QSORTx([s])[,n[,y%()]]
  1193.  
  1194.  
  1195. üQSORTofstring-arraysÇ
  1196.  
  1197. Astring-arraycanbesortedinthesamethreewaysasdescribedfor
  1198. number-arrays.Ifyouhavecreatedanindex-arraywithlast_name$(),you
  1199. couldprintanalphabeticallist:
  1200.      FORi=0TOlast
  1201.        PRINTfirst_name$(index%(i))'last_name$(index%(i))
  1202.      NEXTi     
  1203.  
  1204. Therearetwoextrapossibilitieswithstring-arrays.
  1205.  
  1206.  
  1207. ÇForthefirstpossibility,createabyte-arrayandfillwithappropriate
  1208. ASCII-values:
  1209.      DIMascii|(255)
  1210.      ARRAYFILLascii|(),32!CHR$(32)isthespace-character
  1211.      FORi=48TO57
  1212.        ascii|(i)=i            !0-9
  1213.      NEXTi
  1214.      FORi=65TO90
  1215.        ascii|(i)=i      !A-Z
  1216.      NEXTi
  1217.      FORi=97TO122
  1218.        ascii|(i)=SUB(i,32)    !a-zconvertedtoA-Z
  1219.      NEXTi
  1220. Allcharactersthatarenotnumbersorletterswillbetreatedasaspace
  1221. (ASCII-value32).Usethearrayascii|()forsortingastring-array:
  1222.      QSORTx$()WITHascii|()
  1223. Now'Atari'and'ATARI'aretreatedexactlythesame,becausethe
  1224. interpreterusesthearrayascii|()toconvertlowercaseletterstempora⑨
  1225. rilytouppercaseêbeforeÇsorting.Youcaneventreattheinternational
  1226. characters(ASCII-values>127)correctly,e.g.ascii|(129)=85.Useafew
  1227. DATA-linestoaddthecorrectASCII-value,likethis:
  1228.      DATA128,67,129,85,130,69
  1229. Youcancombinethismethodwithanindex-arrayaswell.Thecorrect
  1230. syntaxis:
  1231.      QSORTx$([s])WITHb|()[,n[y%()]]
  1232. Ifyouhavedoneyourhomework,youshouldnowbeabletowriteaclever
  1233. alphabeticalsorting-programyourself.Youwantedtobecomeanexpert,
  1234. didn'tyou?CompareyourprogramwiththeProceduresAscii.qsortand
  1235. String.index.qsort:
  1236.      PROCEDURE ascii.qsort(VAR txt$())
  1237.        IF DIM?(ascii|())=0
  1238.          @initio.ascii.array
  1239.        ENDIF
  1240.        QSORT txt$() WITH ascii|()
  1241.      RETURN
  1242.      ' 
  1243.      PROCEDURE initio.ascii.array
  1244.        LOCAL i,code1,code2
  1245.        DIM ascii|(255)
  1246.        ARRAYFILL ascii(),32           ! fill with space-character
  1247.        FOR i=48 TO 57
  1248.          ascii|(i)=i                  ! 0 - 9
  1249.        NEXT i
  1250.        FOR i=65 TO 90
  1251.          ascii|(i)=i                  ! A - Z
  1252.        NEXT i
  1253.        FOR i=97 TO 122
  1254.          ascii|(i)=SUB(i,32)          ! a - z, converted to A - Z
  1255.        NEXT i
  1256.        RESTORE ascii.data
  1257.        REPEAT
  1258.          READ code1,code2
  1259.          ascii|(code1)=code2
  1260.        UNTIL code1=0
  1261. Ç       '
  1262.        ascii.data:
  1263.        ' *** format : ASCII-code,replacement
  1264.        DATA 128,67,129,85,130,69,131,65,132,65,133,65,134,65,135,67
  1265.        DATA 136,69,137,69,138,69,139,73,140,73,141,73,142,65,143,65
  1266.        DATA 144,69,145,65,146,65,147,79,148,79,149,79,150,85,151,85
  1267.        DATA 152,121,153,79,154,85,155,67,158,83,160,65,161,73,162,79
  1268.        DATA 163,85,164,78,165,78,166,65,167,79,176,65,177,79,178,79
  1269.      DATA179,79,180,79,181,79,182,65,183,65,184,79,192,121,193,121
  1270.      DATA225,83,0,0
  1271.      RETURN
  1272.      '
  1273.      PROCEDURE string.index.qsort(switch!,VAR txt$(),index%())
  1274.        ' *** the index-array has to exist already 
  1275.        ' *** if switch!=TRUE, array ascii|() is used 
  1276.        LOCAL last,i
  1277.        last=DIM?(txt$())-1           ! index of last element
  1278.        DIM temp$(last)
  1279.        FOR i=0 TO last
  1280.          temp$(i)=txt$(i)
  1281.        NEXT i
  1282.        FOR i=0 TO last
  1283.          index%(i)=i
  1284.        NEXT i
  1285.        IF switch!
  1286.          IF DIM?(ascii|())=0
  1287.            @initio.ascii.array
  1288.          ENDIF
  1289.          QSORT temp$() WITH ascii|(),last+1,index%()
  1290.        ELSE
  1291.          QSORT temp$(),last+1,index%()
  1292.        ENDIF
  1293.        ERASE temp$()
  1294.      RETURN
  1295.  
  1296. Thesecondextrapossibilitywithstring-arraysistheuseof'OFFSETo'
  1297. toignorethefirst'o'charactersduringsorting.Supposeyouhave
  1298. createdanarrayfiles$()withFILESandwouldliketosortthefilesby
  1299. length:
  1300.      QSORTfiles$()OFFSET13,n
  1301. Thefirstcharacter(eitheraspaceor'*')andthefilename(thenext12
  1302. characters)arenowignoredduringsorting.
  1303.  
  1304.  
  1305. üë6.OPERATORSandNUMERICALFUNCTIONS
  1306. Ç
  1307.  
  1308. ü\Ç
  1309.  
  1310. Theoperator'\'(backslash)isidenticaltoDIV:
  1311.      a=b\c
  1312. Integer-divisionisnotasusefulastheotherinteger-operations,because
  1313. theresultisaninteger.Ofcourseitis,butthiscaneasilyresultin
  1314. largeroundingerrors.
  1315.  
  1316.  
  1317. üPREDandSUCCÇ
  1318.  
  1319. PRED(i)isfasterthani-1andSUCC(i)isfasterthani+1.Bothfunctions
  1320. canalsobeusedwithstrings.Notethecleveruse(ahem)ofSUCCinthe
  1321. followinglinefromtheProcedureTime:
  1322.      MID$(timer$,8)=SUCC(RIGHT$(timer$))
  1323. Therightmostdigitoftimer$(alwayseven)isincreasedwithone.
  1324.  
  1325.  
  1326. üMODÇ
  1327.  
  1328. Ifyouuseacounterinaloopinordertodosomethingeverytimethe
  1329. counterreachesamultipleof10,youcoulddothisasfollows:
  1330.      IFcounterMOD10=0      !multipleof10?
  1331.      (...)                  !yes,dosomething
  1332.      ENDIF
  1333. Youcouldalsouse:
  1334.      IFMOD(counter,10)=0
  1335.      (...)
  1336.      ENDIF
  1337.  
  1338.  
  1339. üBCLRÇ
  1340.  
  1341. InGFA-Basicversion2.xyouusedANDtoclearabit:
  1342.      x|=x|AND&X11111011     !clearbit2ofthisbyte
  1343. Remember,thefirst(rightmost)bitisbit0,soabytecontainsbit0-7
  1344. fromrighttoleft.InGFA-Basic3.0youclearabitsimplywith:
  1345.      x|=BCLR(x|,2)            !clearbit2ofthisbyte
  1346. Butifyouwanttoclearmorethanonebit,youshouldusetheAND-method:
  1347.      x|=x|AND&X11110000     !clearbit0-3ofthisbyte
  1348. Inthiscaseyouuseaso-calledmasktoclearcertainbits.Youcanuse
  1349. ANDalsoasafunction:
  1350.      y|=AND(x|,&X11110000)    !evenfasterthanpreviousexample
  1351. Thiswayyoucantestifabit-mask"fits"avariable:
  1352.      IFAND(x|,mask|)
  1353.      (...)
  1354.      ENDIF
  1355. Anexampleofthismethod:
  1356.      IFAND(BIOS(11,-1),&X1001)
  1357.      (...)             !userpressed<Alternate>+right<Shift>
  1358.      ENDIF
  1359. üBSETÇ
  1360.  
  1361. InGFA-Basic2.xyouneededORtosetabit,butnowyouuseBSET:
  1362.      x|=BSET(x|,1)
  1363. YoustillneedtheOR-methodifyouwanttosetmorethanonebitfast:
  1364.      x|=x|OR&X1010          !setbit1and3
  1365. Themask&X1010isusedtosetbits1and3.ComparethiswiththeAND-
  1366. method,whereê0ÇisusedtoêclearÇabit,whilehereê1ÇisusedtoêsetÇabit.
  1367. YoucanuseORnotonlyasanoperator,butalsoasafunction:
  1368.      y|=OR(x|,&X1010)
  1369.  
  1370.  
  1371. üBCHGÇ
  1372.  
  1373. InsteadofBCHGyoushouldusetheXOR-methodifyouwanttochangemore
  1374. thanonebit(withamask):
  1375.      x|=x|XOR&X1110         !changebit1-3
  1376. XORcanbeusedasafunctionaswell.
  1377.  
  1378.  
  1379. üLOGÇ
  1380.  
  1381. Logarithmswithabaseotherthan10orearecomputedasfollows:
  1382.      LOG(x)/LOG(base)
  1383.  
  1384.  
  1385. üSINQandCOSQÇ
  1386.  
  1387. IfyouaregoingtoconvertSIN(orCOS)intoSINQ(COSQ),you'llhaveto
  1388. changefromradialstodegrees.Forexample,youwouldconvertSIN(x)to
  1389. SINQ(DEG(x)).AlthoughSINQisaboutfivetimesfasterthanSIN,this
  1390. extracomputationmakesthedifferencealittlelessspectacular.Ifyou
  1391. arelucky,thevariablealreadyisindegrees,soyoucanuseSINQ
  1392. immediately.SINQandCOSQshouldnotbeusedifyouneedveryaccurate
  1393. results,onlyifyouplottheresultandarenotgoingtouseitfor
  1394. furthercomputations.ExaminethedifferencebetweentheuseofSIN/COS
  1395. andSINQ/COSQtoseeifthelessaccurateresultisacceptable.InHigh
  1396. resolutiontrysomethinglikethis:
  1397.      fac#2*PI/639
  1398.  DRAW0,200
  1399.      FORx=0TO639
  1400.      y#=SIN(x*fac#)
  1401.      DRAWTOx,200+y#*200
  1402.      NEXTx
  1403.      ~INP(2)
  1404.      CLS
  1405.      '
  1406.      DRAW0,200
  1407.      FORx=0TO639
  1408.      y#=SINQ(DEG(x*fac#))
  1409.      DRAWTOx,200+y#*200
  1410.      NEXTx
  1411.      ~INP(2)
  1412.      CLS
  1413. Ç     '
  1414.      fac#=360/639
  1415.  DRAW0,200
  1416.      FORx=0TO639
  1417.      y#=SINQ(x*fac#)
  1418.      DRAWTOx,200+y#*200
  1419.      NEXTx
  1420.      ~INP(2)
  1421.  
  1422.  
  1423. üEQVÇ
  1424.  
  1425. EQVdoesn'tworkproperly.EQV(0,-1)shouldbe0,butequals-65536.The
  1426. bits16-31arealwaysset:EQVseemstolookatthebits0-15only.
  1427.  
  1428.  
  1429. üCARDandSWAPÇ
  1430.  
  1431. Ifa4-byteinteger(postfix%)consistsoftwowords,youcanextract
  1432. thesewith:
  1433.      low.word=CARD(x%)
  1434.      high.word=CARD(SWAP(x%))
  1435. BothwordsareinterpretedasêpositiveÇnumbers.
  1436.  
  1437. Unfortunately,thereisnoanaloguefunctiontoswapthelowandhigh
  1438. byteofaword.Thatwouldbeusefulifyouwanttoconvertaword
  1439. into/fromIntel-format(MS-DOS).Rotating8bitsshoulddothetrick:
  1440.      FUNCTIONintel.word(x%)
  1441.      RETURNCARD(ROR&(x%,8))     !swaplow/highbyte
  1442.      ENDFUNC
  1443. Nowyoushouldbeabletoextractthelowandhighbyteofaword:
  1444.      low.byte|=BYTE(x)
  1445.      high.byte|=BYTE(@intel.word(x))
  1446.  
  1447.  
  1448. üMAXÇ
  1449.  
  1450. Thisishowyoucouldfindthehighestvalueinaword-array:
  1451.      PROCEDURE max.array(VAR proc(),high)
  1452.        ' *** return highest value of array proc()
  1453.        LOCAL last,n
  1454.        last=DIM?(proc())-1
  1455.        high=proc(1)                !proc(0)ignored
  1456.        FOR n=2 TO last
  1457.          high=MAX(high,proc(n))
  1458.        NEXT n
  1459.      RETURN
  1460. Ioftenstorespecialinformationintheelementwithindex0.
  1461.  
  1462.  
  1463. üCorrelationÇ
  1464.  
  1465. UsetheProcedureCorrelatetodeterminethecorrelationbetweentwo
  1466. arrays.
  1467. üë7.STRINGS
  1468. Ç
  1469.  
  1470. üINSTRÇ
  1471.  
  1472. ThecommandINSTR(a$,b$,i)alwaysreturns'1'ifa$=b$.Fori=1that's
  1473. fine,butnotfori>1.Don'tblameme,I'mjustthemessenger.
  1474.  
  1475.  
  1476. üLSETandRSETÇ
  1477.  
  1478. IfyouuseLSETorRSET,thestringispaddedwithspaces:
  1479.      a$="345"
  1480.      LSETa$="12"
  1481.      PRINTa$       !theinterpreterprints"12",ênotÇ"12345"
  1482.  
  1483. YoucanuseRSETforrightjustificationofcolumns:
  1484.      f$=SPACE$(10)
  1485.      FORi=1TO10
  1486.      RSETf$=text$(i)
  1487.      PRINTf$
  1488.      NEXTi
  1489.  
  1490.  
  1491. üParserÇ
  1492.  
  1493. Parsingastring,youwillfrequentlyhavetosplitthestringintothe
  1494. target$,thestringbeforeandthestringafterthattarget$.The
  1495. followingfunctionscouldbehelpful:
  1496.      FUNCTION before$(source$,target$)
  1497.        ' *** returns part of source$ before target$
  1498.        ' *** returns complete source$ if no target$ found
  1499.        LOCAL p
  1500.        p=INSTR(source$,target$)
  1501.        IF p=0
  1502.          RETURN source$
  1503.        ELSE
  1504.          RETURN LEFT$(source$,p-1)
  1505.        ENDIF
  1506.      ENDFUNC
  1507.      '
  1508.      FUNCTION after$(source$,target$)
  1509.        ' *** returns part of source$ after target$
  1510.        ' *** returns nullstring if no target$ found
  1511.        LOCAL p
  1512.        p=INSTR(source$,target$)
  1513.        IF p=0
  1514.          RETURN ""
  1515.        ELSE
  1516.          RETURN MID$(source$,p+LEN(target$))
  1517.        ENDIF
  1518.      ENDFUNC
  1519.  
  1520.  
  1521. üë8.KEYBOARDINPUT
  1522. Ç
  1523.  
  1524. üINKEY$Ç
  1525.  
  1526. Allkeypressesaresavedinthekeyboard-buffer.Ifyoudon'twantINKEY$
  1527. toreadan"old"key,youshouldfirstclearthebuffer:
  1528.      REPEAT
  1529.      UNTILINKEY$=""     !clearkeyboard-buffer
  1530.      key$=""
  1531.      REPEAT
  1532.      key$=INKEY$       !waitfornewkey
  1533.      UNTILkey$<>""
  1534.  
  1535. Inthefollowingtableyou'llfindafewusefulêdecimalÇASCII-codesyou
  1536. canuseafter'key$=INKEY$'.InthethirdcolumntheêhexadecimalÇscan-code
  1537. ofthekeyisalsomentioned(seeparagraph'KEYGET').
  1538.  
  1539.      êkeyÇ                 êASC(key$)Ç       êscancodeÇ
  1540.      <Backspace>         8             &H0E
  1541.      <Tab>               9             &H0F
  1542.      <Return>and<Enter>   13             &H1Cand&H72
  1543.      <Esc>               27             &H01
  1544.      <Delete>              127             &H53
  1545.  
  1546.      êkeyÇ               êASC(RIGHT$(key$))Ç
  1547.      <F1>                     59             &H3B
  1548.      <F10>                    68             &H44
  1549.      <Shift><F1>             84             &H54
  1550.      <Shift><F10>            93             &H5D
  1551.      <Help>                   98             &H62
  1552.      <Undo>                   97             &H61
  1553.      <Insert>                 82             &H52
  1554.      <ClrHome>                71             &H47
  1555.      <Leftarrow>             75             &H4B
  1556.      <Rightarrow>            77             &H4D
  1557.      <Uparrow>               72             &H48
  1558.      <Downarrow>             80             &H50
  1559.  
  1560. Keysinthesecondpartofthistablereturna2-bytevalueafterINKEY$.
  1561. Youonlyneedthelowbyte,thehighbyteis&H00.That'swhyaStandard
  1562. Globallikehelp$isdefinedas'CHR$(0)+CHR$(98)'.Thenit'seasyto
  1563. checkif<Help>waspressed:
  1564.      IFkey$=help$
  1565.      (...)                  !<Help>
  1566.      ENDIF
  1567. Otherwise,youhavetotestasfollows:
  1568.      IFASC(RIGHT$(key$))=98
  1569.      (...)                  !<Help>
  1570.      ENDIF
  1571. However,readtheparagraph'KEYGET'fortheultimatekeypress-processor.
  1572.  
  1573. ÇIfyouarejustwaitingforanykeypress,youcoulduseeitherofthe
  1574. followingmethods(clearthekeyboard-bufferfirst):
  1575.      ~INP(2)             !myfavourite
  1576.      '
  1577.      KEYGETcode%        !perhapsthisisclearerinalisting
  1578.      '
  1579.      REPEAT              !aloopisalsopossible
  1580.      UNTILLEN(INKEY$)
  1581. ThelattermethodisneededifyouarewaitingforanykeypressêorÇany
  1582. mouse-click:
  1583.      REPEAT
  1584.      UNTILLEN(INKEY$)ORMOUSEK
  1585.  
  1586.  
  1587. üINPUTÇ
  1588.  
  1589. Ifyoudon'twantthequestionmarktoappearafterINPUT,use:
  1590.      LOCATEcol,lin
  1591.      INPUT"",txt$
  1592. Thenullstringandthecommaareessential.Mostofthetimeyou'llneed
  1593. somethinglike:
  1594.      LOCATEcol,lin
  1595.      INPUT"Enteryourname:",name$
  1596. Butiftheinstruction-lineisnotthesameastheINPUT-line,use:
  1597.      PRINTAT(col1,lin1);"Enteryourname:"
  1598.      LOCATEcol2,lin2
  1599.      INPUT"",name$
  1600.  
  1601. AfterINPUT,theusercanpress<Insert>toswitchbetweenInsert-modeand
  1602. Overwrite-mode.Ihavenotbeenabletodiscoverhowtoinputcharacter-
  1603. codes0-31afterINPUT.It'snotimportantanyway,butIreadsomewhere
  1604. youcoulduse<Alternate>forthispurpose.TheAlternate-methodcanbe
  1605. usedforcharacter-codes128-255(not127).Inthefollowingtableyou'll
  1606. findsomeimportantcharacterswiththedecimalASCII-code:ê
  1607.  
  1608. Ç êcharacterÇ êASCII-codeÇ   êcharacterÇ êASCII-codeÇ êcharacterÇ êASCII-codeÇ
  1609.  
  1610.      á    -    160          é    -    130         í    -   161
  1611.      à    -    133          è    -    138         ì    -   141
  1612.      ä    -    132          ë    -    137         ï    -   139
  1613.      â    -    131          ê    -    136         î    -   140
  1614.  
  1615.      ó    -    162       ú   -   163         ÿ    -   152
  1616.      ò    -    149       ù    - 151          ß    -   158
  1617.      Ö    -    148       ü    - 129
  1618.      ô    -    147       û    - 150
  1619.  
  1620.      α    -    224       ≡   -   240         ½    -    171
  1621.      β    -    225       ±   -   241         ¼    -   172
  1622.      δ    -    235       ≥   -   242         ²    -    253
  1623.      µ    -    230       ≤    -  243
  1624.      π    -    227       ÷    -  246
  1625.      τ    -    231       ≈    -  247
  1626.  
  1627. Ç     ¢    -    155       ©    -    189
  1628.      £    -    156       §    -    221
  1629.      ƒ    -    159
  1630. IfyouwanttouseoneofthesecharactersafterINPUT,youshouldhold
  1631. <Alternate>down,enterthecode,andrelease<Alternate>.Ihopeyour
  1632. printer-drivercoulddigestthistable...
  1633.  
  1634. Youcanuse<Backspace>,<Delete>,<Leftarrow>and<Rightarrow>onan
  1635. INPUT-line,butalso:
  1636.      <Uparrow>     -cursortostartofinput-line
  1637.      <Downarrow>   -cursortoendofline
  1638.      <Esc>          -eraseline
  1639. Thefirsttwofeelslightlyunnatural,Iwouldpreferittheotherway:up
  1640. toend,downtostart.
  1641.  
  1642. BothINPUTandLINEINPUTuseaspecialcursor,soitdoesn'tmakemuch
  1643. sensetouseXBIOS21(Curscon)todosomethinginterestingwiththeTOS-
  1644. cursor.
  1645.  
  1646.  
  1647. üINPUT$
  1648. Ç
  1649. Fortheinputofasecretpassword,youcouldusesomethinglike:
  1650.      PRINT"typepassword(5characters):";
  1651.      code$=INPUT$(5)
  1652. Thepassworddoesnotappearonthescreen.
  1653.  
  1654. ü
  1655. LINEINPUTÇ
  1656.  
  1657. LINEINPUTusestheunderscore(_)asthecursorinawindow.Afteryou
  1658. press<Return>,theunderscoreisnotcompletelyerased.Therightmost
  1659. pixelremainsvisible.IthinkthisisaGEM-bug.
  1660.  
  1661.  
  1662. üKEYTESTÇ
  1663.  
  1664. TheKEYTEST-functiondoesnotrespondtokeyssuchas<Help>,<Undo>,etc.
  1665.  
  1666.  
  1667. üKEYGETÇ
  1668.  
  1669. KEYGETwaitsforakeypress,justlikeINP(2).ButKEYGETisfarmore
  1670. flexible,becauseitreturnstheASCII-codeêandÇthescan-codeofanykey
  1671. êandÇalsothestateofthespecialkeys<Shift>,<Control>,<Alternate>and
  1672. <CapsLock>.ConsultyourmanualfortablesofASCII-codesandscan-codes
  1673. (intheparagraph'INKEY$'youalreadyencounteredsomeimportantcodes).
  1674. Studythefollowingexampletogetanimpressionoftheeasywayyoucan
  1675. examineallkeypresseswithKEYGET:
  1676.  
  1677. Ç     @initio_keyget!assignvariablestothethreecodes
  1678.      '
  1679.      DO
  1680.      KEYGETget_code%
  1681.      @keyget!processkeypressthere(notincluded)
  1682.      LOOP
  1683.      '
  1684.      PROCEDUREinitio_keyget
  1685.      ABSOLUTEascii|,V:get_code%+3
  1686.      ABSOLUTEscan|,V:get_code%+1
  1687.      ABSOLUTEstatus|,V:get_code%
  1688.      RETURN
  1689.  
  1690. YouwillhavetowriteyourownKeyget-Procedure.Youcancheckifanyof
  1691. thespecialkeyshasbeenpressed,byusingBTST(status|,bit):
  1692.      bit0=Right<Shift>
  1693.      bit1=Left<Shift>
  1694.      bit2=<Control>
  1695.      bit3=<Alternate>
  1696.      bit4=<CapsLock>
  1697. Youcoulddiscoveriftheuserhadpressed<Control><Downarrow>with:
  1698.      IFscan|=&H50ANDBTST(status|,2)
  1699.      (...)
  1700.      ENDIF
  1701.  
  1702. IfyouareêonlyÇinterestedinmonitoringthefivespecialkeys,youcould
  1703. useBIOS11(Kbshift)aswell:
  1704.      status|=BIOS(11,-1)
  1705. Usethesametableasabovetotestifbit0-4isset.
  1706.  
  1707. Youareadvisedtoclearthekeyboard-bufferbeforeleavingtheProcedure
  1708. Keyget.
  1709.  
  1710. Inmostcasesthescan-codeofakeyisthesame,whetheryoupresseda
  1711. specialkeysimultaneouslyornot.Butwatchoutforthefollowing
  1712. exceptions!For<Shift><F1>to<Shift><F10>thescan-codes&H54to&H5D
  1713. arereturned(ênotÇ&H3Bto&H44).OnanMS-DOScomputerthesecodesare
  1714. usedforthekeysF11toF20.Thecombinations<Control><LeftArrow>
  1715. (&H73)and<Control><RightArrow>(&H74)alsohavespecialcodes.Blame
  1716. MS-DOS.Thecombinations<Alternate><1>to<Alternate><=>havethe
  1717. specialcodes&H78to&H83.That'sALT1toALT=forMS-DOS.
  1718.  
  1719.  
  1720. üKEYLOOKÇ
  1721.  
  1722. Accordingtoanunconfirmedreport,KEYLOOKdoesnotfunctionproperly
  1723. withthepre-BlitterTOS.
  1724. ü
  1725.  
  1726. üKEYPRESSÇ
  1727.  
  1728. KEYPRESSusesthesame4-byteformatasKEYGET:&Hccss00aa.Inityou
  1729. willrecognizetheASCII-code(&Haa),thescan-code(&Hss)andthecode
  1730. forthespecialkeys(&Hcc).Ifyouwanttosimulatethepressingofakey
  1731. inanAlertbox,youwillhavetosendboththeASCII-codeandthescan-
  1732. code.Use&H1C000Dtosimulatethepressingof<Return>.Or&H04620062for
  1733. <Control><Help>,althoughthatcertainlywon'thelpinanAlertbox.If
  1734. youdon'tneedthescan-code(e.g.withINPUT),youcanusejustKEYPRESS
  1735. &Haa.
  1736.  
  1737. ü
  1738. KEYDEF
  1739.  
  1740. ÇTheeditoralwaysusesKEYPAD&X101110,soyouwillhavetosetbit4
  1741. yourself(e.g.KEYPAD&X10000)beforeyouwillbeabletouseKEYDEFin
  1742. yourprogram.
  1743.  
  1744.  
  1745. üKeyboard
  1746. Ç
  1747. AsfarasIknow,therearefourdifferentkeyboardsavailable:USA
  1748. (QWERTY),English(QWERTY),German(QWERTZ)andFrench(AZERTY).Thekey
  1749. withscan-code&H2B(totherightof<Return>)hasadifferentASCII-code
  1750. ineachversion:
  1751.      êversionÇ   êASCII-codeÇ     êcharacterÇ
  1752.      USA        &H5C (92)       \
  1753.      English &H23 (35)       #
  1754.      German   &H7E (126)      ~
  1755.      French     &H40 (64)       @
  1756. YoucoulduseXBIOS16(Keytbl)todeterminethekeyboard-version:
  1757.      PROCEDURE keyboard.version
  1758.        SELECT PEEK(LPEEK(XBIOS(16,L:-1,L:-1,L:-1))+&H2B)
  1759.        CASE &H5C
  1760.          usa.keybrd!=TRUE
  1761.        CASE &H23
  1762.          english.keybrd!=TRUE
  1763.        CASE &H7E
  1764.          german.keybrd!=TRUE
  1765.        CASE &H40
  1766.          french.keybrd!=TRUE
  1767.        ENDSELECT
  1768.      RETURN
  1769.  
  1770. Youshouldtakeintoaccountthedifferencesbetweenthekeyboard-versions
  1771. ifyouarewritingaprogramthatshouldrunsmoothlyinanycountry.
  1772.  
  1773. ÇInthefollowingtableIhavegatheredallkeysthathaveênotÇthesame
  1774. meaningonthefourkeyboard-versions:
  1775.  
  1776.      êscancodeÇ      êUSAÇ     êEnglishÇ   êGermanÇ    êFrenchÇ
  1777.      &H0C         -         -         ß         )      
  1778.      &H0D         =         =         -         '
  1779.      &H10         Q         Q         Q         A
  1780.      &H11         W         W         W         Z
  1781.      &H15         Y         Y         Z         Y
  1782.      &H1A         [         [         Ü         [
  1783.      &H1B         ]         ]         +         ]
  1784.      &H1E         A         A         A         Q
  1785.      &H27         ;         ;         ö         M
  1786.      &H28         '         '         Ä         \
  1787.      &H29         `         `         #         `
  1788.      &H2B         \         #         ~         @
  1789.      &H2C         Z         Z         Y         W
  1790.      &H32         M         M         M         ,
  1791.      &H33         ,         ,         ,         ;
  1792.      &H34         .         .         .         :
  1793.      &H35         /         /         -         =
  1794.      &H60        none      \         <         <
  1795.  
  1796. Ifyouaregoingtouseanyscan-codefromthistable,youshouldbevery
  1797. careful.It'snotnicetoaskaGermanusertopress<Y>,buttestfor
  1798. scan-code&H15inyourprogram...
  1799.  
  1800. Ifyouinsistondoingthingsthehardway,youcanfindtheASCII-value
  1801. thatisassignedtoakeywithXBIOS16.Actuallytherearethreetables:
  1802. oneforanormalkeypress,oneforashiftedkeyandoneforakeypress
  1803. withCapsLockon:
  1804.      keytbl%=LPEEK(XBIOS(16,L:-1,L:-1,L:-1))
  1805.      shift%=keytbl%+&H80
  1806.      capslock%=shift%+&H80
  1807. NowyoucanfindtheASCII-codeforanyscan-code(<&H80):
  1808.      ascii=PEEK(keytbl%+scancode)       !normalkey
  1809.      ascii=PEEK(shift%+scancode)        !shiftedkey
  1810.      ascii=PEEK(capslock%+scancode)     !CapsLockon
  1811.  
  1812.  
  1813. üKeyclick,KeyrepeatandCapsLockÇ
  1814.  
  1815. Normally,youneedtheKeyclickasanaudiblefeedback.Sometimesyouhave
  1816. toswitchtheKeyclickoff,e.g.whileanXBIOS32songisplaying:
  1817.      PROCEDURE key.click(switch!)
  1818.      IF switch!
  1819.          SPOKE &H484,BSET(PEEK(&H484),0)     ! keyclick on
  1820.        ELSE
  1821.          SPOKE &H484,BCLR(PEEK(&H484),0)     ! keyclick off
  1822.        ENDIF
  1823.      RETURN
  1824.  
  1825. ÇIfyourprogramreactsslowlyafterakeypress,youprobablyhaveto
  1826. switchtheKeyrepeattemporarilyoff:
  1827.      PROCEDURE key.repeat(switch!)
  1828.        IF switch!
  1829.          SPOKE &H484,BSET(PEEK(&H484),1)     ! key-repeat on
  1830.        ELSE
  1831.          SPOKE &H484,BCLR(PEEK(&H484),1)     ! key-repeat off
  1832.        ENDIF
  1833.      RETURN
  1834.  
  1835. YoucanswitchCapsLockonoroffwith:
  1836.      PROCEDURE caps(switch!)
  1837.        IF switch!
  1838.          ~BIOS(11,BSET(BIOS(11,-1),4))       ! CapsLock on
  1839.        ELSE
  1840.          ~BIOS(11,BCLR(BIOS(11,-1),4))       ! CapsLock off
  1841.        ENDIF
  1842.      RETURN
  1843.  
  1844.  
  1845.  
  1846. üë9.SCREENOUTPUT
  1847. Ç
  1848.  
  1849. üPRINTÇ
  1850.  
  1851. ItisveryimportanttoknowifPRINTwillbeusedontheso-calledTOS-
  1852. screen(nowindowsopened),orinawindow.TOSemulatestheVT52-terminal
  1853. ofDigitalEquipment,soifyouPRINTontheTOS-screen,theVT52-codes
  1854. willbeinterpretedascommands.Butinawindowthesecodesareprinted
  1855. ascharacters!
  1856.  
  1857. InbothHighandMediumresolutionyoucanPRINT25linesof80
  1858. characters,butinLowresolutionit's25linesof40charactersonly.
  1859.  
  1860. Normallyyoucan'tPRINTacharacteratposition(80,25)inHighorMedium
  1861. resolution,orat(40,25)inLowresolution.Trythefollowing:
  1862.      PRINTAT(80,25);"X";
  1863. andyouwillseethatalinefeedisexecutedautomatically,inspiteof
  1864. thesemicolonafter"X".OntheTOS-screenyoucanputacharacteratthis
  1865. positionbyusingtheVT52-command'wrapoff':
  1866.      PRINTAT(80,25);"*wX";        !usetheEscape-characterinsteadof*
  1867. After'Escw'thelinefeedissuppressed.Theeasiestwaytoenterthe
  1868. Escape-characterintheGFA-editoristohold<Alternate>downandthento
  1869. enter<2><7>.IfyouPRINTastringthatdoesn'tfitonthecurrentline,
  1870. theremainingcharactersareeitherprintedonthenextline('Escv',the
  1871. defaultintheinterpreter,ênotÇinacompiledprogram),ordiscarded
  1872. ('Escw').Actually,after'Escw'allcharactersuptothefirstCHR$(10)
  1873. orCHR$(13)arediscarded.
  1874.  
  1875. It'simpossibletoPRINTcharacterswithASCII-code0-31ontheTOS-
  1876. screen.However,youcanprintanycharacterwith:
  1877.      OUT5,code
  1878. Ifnecessary,useLOCATEfirst.
  1879.  
  1880. Afteropeningawindow(OPENWx)thecommandDEFTEXTwillchangesizeand
  1881. colourofPRINTedtextaswell!OneadvantageisthatyoucannowPRINTin
  1882. differentcoloursonthescreen.
  1883.  
  1884. OntheTOS-screen,allPRINTedtexthasthesamecolour.Thiscolouris
  1885. determinedbycolour-index1andisalsousedfortheAlert-boxandthe
  1886. Fileselector.Thebackgroundonthescreenisdeterminedbycolour-index
  1887. 0.ThiscolourisusedafterCLS.
  1888.  
  1889. ItispossibletoPRINTindifferentcoloursontheTOS-screen,byusing
  1890. theVT52-code'Escb'.ThebackgroundofPRINTedtextcanbechangedwith
  1891. VT52-code'Escc'.Usethefollowingfunctionstoexperiment:
  1892.      DEFFNink$(color)=CHR$(27)+"b"+CHR$(color)
  1893.      DEFFNpaper$(color)=CHR$(27)+"c"+CHR$(color)
  1894. Usethecolour-tablefromtheparagraph'SETCOLOR'orbepreparedto
  1895. becomeveryfrustrated.IusetheStandardArraycolor.index()asthe
  1896. colour-tableinmyprograms,soIchangethecolourofthePRINTedtextor
  1897. theback-groundwiththeStandardFunctions:
  1898.      DEFFNink$(color)=CHR$(27)+"b"+CHR$(color.index(color))
  1899.      DEFFNpaper$(color)=CHR$(27)+"c"+CHR$(color.index(color))
  1900. ÇRemember,theVT52-codeshavetobePRINTedtobecomeeffective,like
  1901. this :
  1902.      PRINT@ink$(red);@paper$(green);"thistextiseye-catching"
  1903. Notethespacesatbeginningandendofthestringtoemphasizethetext-
  1904. colouragainstthebackground-colour.Ofcourseyouhavetodeclarethe
  1905. variablesredandgreenfirst(usuallycolour-index2and3;orifyou
  1906. don'tusetheVDIcolour-index,trythenumbers1and2).Idefinethe
  1907. defaultcoloursasStandardGlobalsinmyprograms.BeforeIforget,it
  1908. won'tworkinHighresolution.Sorry,couldn'tresistthatone.
  1909.  
  1910. InordertocatchtheeyeoftheuserinHighresolutionyoucanPRINT
  1911. reverseontheTOS-screen:
  1912.      PRINT"thisis*pIMPORTANT*q"    !enterEscinsteadof*
  1913. EntertheEscape-characterintheusualway.Noteagaintheextraspace
  1914. bothbeforeandafterthewordthatshouldstandout.Ofcourseyoucould
  1915. alsouseCHR$(27):
  1916.      PRINT"thisis";CHR$(27);"pIMPORTANT";CHR$(27);"q"
  1917. Moredifficulttoreadonthescreen,buteasiertoLlist.Iusethe
  1918. StandardFunctionRev$inallprograms:
  1919.      DEFFN rev$(txt$)=CHR$(27)+"p"+txt$+CHR$(27)+"q"
  1920.  
  1921. IfyouuseacommawithPRINT,thecursorwilljumptothenexttabulator-
  1922. stop.Tab-stopsareatposition1,17,33,49and65.Trythefollowingto
  1923. seewhatImean(inHighorMediumresolution):
  1924.      PRINT"1","17","33","49","65","1","17"
  1925. Ifyouusethecommaafterthelasttab-stop,alinefeedisexecutedand
  1926. thecursorjumpstothefirsttab-stoponthenextline.
  1927.  
  1928. Theeasiestwaytousedoublequotesisbyusingdoubledoublequotes
  1929. (readthistwicetomakesureyouunderstandit):
  1930.      PRINT"doublequotesprintedthe""easy""way"
  1931. InaDATA-lineasingledoublequotesuffices:
  1932.      DATA"lookMa,"doublequotes"again"
  1933. Or,simply:
  1934.      DATAlookMa,"doublequotes"again
  1935.  
  1936. TrytheProcedureFastprintinHighresolutionifyoufindPRINTtooslow.
  1937. ThisProcedureprintsaboutfourtimesfaster!VT52-commandsareignored,
  1938. becausecharactersarecopiedstraightfromthefont-tabletothescreen.
  1939.  
  1940.  
  1941. üLOCATEÇ
  1942.  
  1943. ThesyntaxofPRINTATandLOCATEisnowlessconfusing:
  1944.      PRINTAT(column,line)
  1945. LOCATEcolumn,line
  1946. InolderversionsofGFA-BasicitwasLOCATEline,column.Checkthisif
  1947. yourunanoldprogramandtextisPRINTedonthewrongplace.
  1948.  
  1949.  
  1950. üPRINTTABÇ
  1951.  
  1952. PRINTTABbehavesstrangelyifthepositionisgreaterthan80.Trythe
  1953. followinginHighorMediumresolution:
  1954.      FORi=0TO30
  1955.      PRINTTAB(i*20);i;
  1956.      NEXTi
  1957. Onewaytosolvethisproblemis:
  1958.      PRINTTAB(MOD(i*20,80));i;         !dousesemicolons
  1959. ButIthinkthisisaGFA-bugthatprobablywillbecorrectedinfuture
  1960. versions.
  1961.  
  1962. YoucancombineTABwithPRINTATandwithPRINTUSING:
  1963.      PRINTAT(1,1);"1";TAB(40);"40"
  1964.      PRINTTAB(40);USING"##",40
  1965.  
  1966.  
  1967. üSetscreen(XBIOS5)
  1968.  
  1969. ÇWithXBIOS5(Setscreen)itispossibletochangetheresolutionfromLow
  1970. toMediumandfromMediumtoLow.Unfortunately,GEMignorestheswitch,
  1971. soGEM-commands(e.g.ALERT,TEXT,MOUSE)donotworkproperly!Butyou
  1972. couldchangefromLowtoMediumresolutiontoshowtextontheTOS-screen
  1973. withPRINT(andVT52-commands).Mostuserswillbegratefulforthe
  1974. improvedreadabilityofthetext:
  1975.      ~XBIOS(5,L:-1,L:-1,1)    !switchfromLowtoMedium
  1976.      (...)                    !printtextinMediumresolution
  1977.      ~XBIOS(5,L:-1,L:-1,0)    !andgobacktoLow
  1978. Ifyouchangetheresolution,theVT52-emulatorisautomatically
  1979. initialised.You'llprobablyhavetoadjustthepalettebeforeyoucan
  1980. readthetextwithoutsun-glasses.Don'tforgettosaveandrestorethe
  1981. oldpalette.
  1982.  
  1983. XBIOS5isveryusefulifyouwouldliketodrawonascreenbefore
  1984. showingittotheuser.Drawingonan"invisible"screenisindeed
  1985. possible,becausetheoperatingsystemusestwoscreens:thephysical
  1986. screen(visibleonyourmonitor)andthelogicalscreen(usually,butnot
  1987. necessarily,thesameasthephysicalscreen).Allgraphical(GEM-)com-
  1988. mands,includingtheTEXT-command,arealwayssenttothelogicalscreen.
  1989. ButTOSwillsendPRINT-commandstotheêphysicalÇscreen,unlessyou've
  1990. openedawindow!Iftheaddressoflogicalandphysicalscreenisnotthe
  1991. same,youhaveyourinvisiblescreen(exceptforPRINTingontheTOS-
  1992. screen).TheaddressofthelogicalscreenêmustÇbeamultipleof256.
  1993. StudytheProceduresInitio.logical.screen,Swap.screenand
  1994. Restore.physical.screentoseehowyoucouldusethedescribedmethodfor
  1995. animation:
  1996.      PROCEDURE initio.logical.screen
  1997.        ' *** global :   SCREEN.1%   SCREEN.2%
  1998.        DIM screen.2|(32256)               
  1999.        screen.2%=VARPTR(screen.2|(0))
  2000.        screen.2%=screen.2%+256-(screen.2% MOD 256)
  2001.        screen.1%=physbase%
  2002.        ~XBIOS(5,L:screen.2%,L:-1,-1)  ! invisible screen.2 is now active
  2003.      RETURN
  2004. Ç     ' 
  2005.      PROCEDURE swap.screen
  2006.        ' *** physical and logical screen are swapped
  2007.        SWAP screen.1%,screen.2%
  2008.        VSYNC                                   ! avoid flash
  2009.        ~XBIOS(5,L:screen.2%,L:screen.1%,-1)    ! swap the screens
  2010.      RETURN
  2011.      ' 
  2012.      PROCEDURE restore.physical.screen
  2013.        ~XBIOS(5,L:physbase%,L:physbase%,-1)
  2014.      RETURN
  2015.  
  2016. OnsomeST-computersXBIOS5doesnotfunctionproperlyafterinstallation
  2017. ofaRAM-disk.Inthatcaseyoucouldchangetheaddressofthelogical
  2018. screenwith:
  2019.      VSYNC
  2020.     SLPOKE&H45E,adr%
  2021.  
  2022.  
  2023. üFontÇ
  2024.  
  2025. TOShasthreebuilt-insystem-fonts.ThedefaultPRINT-fontforHigh
  2026. resolutionisthe8x16font(equalsDEFTEXT,,,13forTEXT),whilethe8x8
  2027. font(equalsDEFTEXT,,,6)isusedinMediumandLowresolution.Youcan
  2028. switchbetweenthesetwofontswiththefollowingProcedures:
  2029.      PROCEDURE font.8x16
  2030.        LOCAL a$,adr%
  2031.        a$=MKI$(&HA000)+MKI$(&H2009)+MKI$(&H4E75)   
  2032.        adr%=VARPTR(a$)
  2033.        adr%=C:adr%()         ! address of font-table
  2034.        {INTIN}={adr%+8}      ! pointer to 8x16 system-font 
  2035.        VDISYS 5,2,0,102      
  2036.      RETURN
  2037.      ' 
  2038.      PROCEDURE font.8x8
  2039.        LOCAL a$,adr%
  2040.        a$=MKI$(&HA000)+MKI$(&H2009)+MKI$(&H4E75)   
  2041.        adr%=VARPTR(a$)
  2042.        adr%=C:adr%()         ! address of font-table
  2043.        {INTIN}={adr%+4}      ! pointer to 8x8 system-font
  2044.        VDISYS 5,2,0,102      
  2045.      RETURN     
  2046. BothProceduresseemtohaveproblemswiththeaccessoryQUICKST,butI
  2047. neveruseitwithGFA-Basicbecausethereareotherproblems(INPUT)as
  2048. well.IfIdon'tuseit,howdidIdiscoverthis?Goodquestion.Thethird
  2049. fontisusedforicons,butforsomereasoncannotbecomethecurrent
  2050. system-font.TheVDI-functionseemstoworkonlywithfontscontaining
  2051. charactersofwidth8pixels.Thefunctionisnotofficiallydocumented
  2052. byAtari(?).
  2053.  
  2054. ÇYoucanreplacethesystem-fontbyafontthathasbeencreatedwith
  2055. FONTKITbyJeremyHughes(4114byteA1_xxxxx.FONfileforHigh
  2056. resolution).UsetheProcedureChange.fontforthispurposeandcallthe
  2057. ProcedureNormal.fonttorestoretheoriginalsystem-font:
  2058.      PROCEDURE change.font
  2059.        ' *** global :   NEW.FONT!   NORMAL.FONT%
  2060.        LOCAL adr%,new.font%
  2061.        '
  2062.        ' *** load A1_xxxxx.FON file (4114 bytes) here
  2063.        INLINE new.font%,4114
  2064.        '
  2065.        adr%=L~A-22
  2066.        normal.font%={adr%}
  2067.        SLPOKE adr%,new.font%
  2068.        new.font!=TRUE
  2069.      RETURN
  2070.      '
  2071.      PROCEDURE normal.font
  2072.        IF new.font!
  2073.          SLPOKE L~A-22,normal.font%
  2074.          new.font!=FALSE
  2075.        ENDIF
  2076.      RETURN
  2077. IhavenotyetdiscoveredhowtouseaFONTKIT-fontwithTEXT.Yes,I
  2078. couldloadanewfontafterinstallingGDOS,butthat'snotwhatI'm
  2079. lookingfor.Isthereaquickandnot-dirtywaytoconvinceGEMthatanew
  2080. fonthasbeeninstalled?
  2081.  
  2082. Afont-tableforthe8x16fontoccupies4096bytes(16bytes/character,
  2083. 256characters).AFONTKIT-fontusuallyhasanameattachedattheend,
  2084. that'swhyIreserve4114bytes.TOSignoresthenamecompletely,it's
  2085. onlyusedbytheaccessoryFONSEL.ACC.Youcanloadany4096-bytefontin
  2086. theProcedureChange.font,youdon'tevenhavetochange4114into4096.
  2087. Althoughyoulose18bytesifyoudon't.
  2088.  
  2089.  
  2090. üë10.PRINTER
  2091. Ç
  2092.  
  2093. üPrinterreadyÇ
  2094.  
  2095. Ifyousenddatatoyourprinter(HARDCOPY,LPRINT,etc.),yourSTwill
  2096. wait30looooooongsecondsiftheprinterhappenstobenotready.Always
  2097. checkiftheprinterisreadybeforesendingdatatotheprinter,e.g.by
  2098. callingthefollowingProcedure:
  2099.      PROCEDUREprinter.ready
  2100.      LOCALk
  2101.      DO
  2102.      EXITIFGEMDOS(17)
  2103.          ALERT3,"printer||notready!!",1,"OK",k
  2104.      LOOP
  2105.      RETURN
  2106.  
  2107.  
  2108. üHARDCOPYÇ
  2109.  
  2110. YoucansendascreendumptotheprinterbyusingthecommandHARDCOPYor
  2111. bypressing<Alternate><Help>.InêbothÇcasesyoucanabortthescreendump
  2112. bypressing<Alternate><Help>.
  2113.  
  2114. YoucanuseCONTROL.ACCtochangetheprinter-parameters.Don'tforgetto
  2115. savethedesktop,inordertostoretheseparametersinthefile
  2116. DESKTOP.INF.Lookfor'#b'withyourdisk-editorifyou'recurious.The
  2117. parameterswillonlybereadfromDESKTOP.INFifCONTROL.ACCisinstalled
  2118. afterareset!IsuggesttheuseofXBIOS33(Setprt)inaprograminstead
  2119. ofusingCONTROL.ACC.ForascreendumpfromtheHighresolutionscreento
  2120. anEpson-compatibleprinter,clearbit1andsetbit2:
  2121.      PROCEDUREscreendump
  2122.      ~XBIOS(33,&X100)    !screendumptoEpson(-compatible)printer
  2123.      HARDCOPY
  2124.      RETURN
  2125. Ifyousetbit2,TOSassumesyouconnectedanEpson-printer(960
  2126. pixels/line).Clearbit2andTOSassumesyouhaveanAtari-printer(1280
  2127. pixels/line).
  2128.  
  2129. IfyouuseHARDCOPY,thewidth/heightratiooftheprintoutdoesnot
  2130. correspondwiththatofthescreen.Forareasonablyfast1:1screendump,
  2131. studytheProcedureHigh.screendump.epson(EpsonFX-80,orother9-pin
  2132. Epson-compatibleprinter)ortheProcedureHigh.screendump.star24(24-pin
  2133. StarLC24-10):
  2134.      PROCEDURE high.screendump.star24
  2135.        LOCAL m$,b$,k,scrn.start%,col,b%,x,d%,p|,b1|,b2|,b3|,n
  2136.       lf$=CHR$(10)
  2137.       ff$=CHR$(12)
  2138.       DEFFN bit.image$(m,d)=CHR$(27)+"*"+CHR$(m)+CHR$(MOD(d,256))+
  2139.                                                             CHR$(d/256)
  2140.       DEFFN line.space$(n)=CHR$(27)+"3"+CHR$(n)   
  2141.       initialize$=CHR$(27)+"@"
  2142.       scrn.start%=XBIOS(2)
  2143.       '
  2144. Ç      LPRINT initialize$;
  2145.       FOR col=0 TO 79
  2146.         b%=scrn.start%+col
  2147.         LPRINT SPC(8);              
  2148.         LPRINT @line.space$(24);   
  2149.         LPRINT @bit.image$(33,800);
  2150.         FOR x=399 TO 0 STEP -1
  2151.           d%=ADD(b%,MUL(x,80))
  2152.           p|=BYTE{d%}
  2153.           IF p|=0
  2154.             OUT 0,0,0,0,0,0,0
  2155.           ELSE
  2156.             CLR b1|,b2|,b3|
  2157.             IF BTST(p|,0)
  2158.               b1|=7
  2159.             ENDIF
  2160.             IF BTST(p|,1)
  2161.               ADD b1|,56
  2162.             ENDIF
  2163.             IF BTST(p|,2)
  2164.               ADD b1|,192
  2165.               b2|=1
  2166.             ENDIF
  2167.             IF BTST(p|,3)
  2168.               ADD b2|,14
  2169.             ENDIF
  2170.             IF BTST(p|,4)
  2171.               ADD b2|,112
  2172.             ENDIF
  2173.             IF BTST(p|,5)
  2174.               ADD b2|,128
  2175.               b3|=3
  2176.             ENDIF
  2177.             IF BTST(p|,6)
  2178.               ADD b3|,28
  2179.             ENDIF
  2180.             IF BTST(p|,7)
  2181.               ADD b3|,224
  2182.             ENDIF
  2183.             OUT 0,b3|,b2|,b1|,b3|,b2|,b1|
  2184.           ENDIF
  2185.         NEXT x
  2186.         LPRINT
  2187.         EXIT IF INKEY$=esc$
  2188.       NEXT col
  2189.       LPRINT ff$;
  2190.       LPRINT initialize$;
  2191.      RETURN
  2192.  
  2193. Foramoreflexibleapproach,studytheProcedureDegas.screendump(Star
  2194. LC24-10,possibleformats:27x17,18x11,13.5x8.5or9x5.5cm).
  2195.  
  2196. ÇItshouldbepossibletosendonlya(GET-)rectangletoyourprinterwith
  2197. XBIOS36(Prtblk)orV_OUTPUT_WINDOW(VDI5,Escape21).Anybodyoutthere
  2198. whoknowshow?
  2199.  
  2200. Never,Irepeat,êneverÇswapdisksduringascreendump,asthiscouldbe
  2201. fatalforthenewdisk.TOSignoresthewrite-protectstateduringa
  2202. screendump,soitwillmissthedisk-swapcompletely.TOSwillusetheold
  2203. FATforthenewdisk,andthatusuallyisfatal(nopunintended).
  2204.  
  2205. IfyouhaveinstalledaGFA-Basicprinter-driver(e.g.PTEPSON.PRG),a
  2206. screendumpseemstobeimpossible.Thebit-imagemodeoftheprintercan't
  2207. beusedafterthedriverhasbeeninstalled.
  2208.  
  2209.  
  2210. üPrinter-commandsÇ
  2211.  
  2212. Mostmatrix-printersrecognizeeitherIBM-orEpson-commands(orboth).I
  2213. usethefollowingProceduretodefinethemostimportantprinter-commands
  2214. formyStarLC24-10.Adaptthedefinitionstoyourownprinter,butstick
  2215. tothenamesfortheglobalvariablesandfunctions.Otheruserscould
  2216. thenuseyourprogramseasilyafterreplacingtheProcedureInitio.printer
  2217. withtheirown:
  2218.      PROCEDURE initio.printer
  2219.        ' *** initializes global printer-variables for Star LC24-10
  2220.        ' *** DIP-switch settings :
  2221.        '     1-1 OFF         2-1 ON
  2222.        '     1-2 ON          2-2 ON
  2223.        '     1-3 OFF         2-3 ON
  2224.        '     1-4 ON          2-4 ON
  2225.        '     1-5 ON          2-5 OFF
  2226.        '     1-6 ON          2-6 OFF
  2227.        '     1-7 ON          2-7 ON
  2228.        '     1-8 ON          2-8 ON
  2229.        '
  2230.        LOCAL c$,f$
  2231.        c$=CHR$(27)
  2232.        f$=CHR$(28)
  2233.        '
  2234.        draft.char$=c$+"x0"
  2235.        lq.char$=c$+"x1"
  2236.        '
  2237.        courier.style$=c$+"k0"+lq.char$
  2238.        prestige.style$=c$+"k2"+lq.char$
  2239.        orator.style$=c$+"k3"+lq.char$
  2240.        script.style$=c$+"k4"+lq.char$
  2241.        '
  2242.        normal.char$=c$+"q0"
  2243.        outlined.char$=c$+"q1"
  2244.        shadow.char$=c$+"q2"
  2245.        outlined.shadow.char$=c$+"q3"
  2246.        '
  2247.        italic.on$=c$+"4"
  2248.        italic.off$=c$+"5"
  2249.        '
  2250. Ç       emphasized.on$=c$+"E"
  2251.        emphasized.off$=c$+"F"
  2252.        '
  2253.        underline.on$=c$+"-1"
  2254.        underline.off$=c$+"-0"
  2255.        '
  2256.        bold.draft$=draft.char$+emphasized.on$+double.on$
  2257.        bold.lq$=lq$+double.on$
  2258.        bold.off$=emphasized.off$+double.off$
  2259.        '
  2260.        superscript.on$=c$+"S0"
  2261.        superscript.off$=c$+"T"
  2262.        subscript.on$=c$+"S1"
  2263.        subscript.off$=c$+"T"
  2264.        '
  2265.        epson.set$=c$+"t0"
  2266.        ibm.set$=c$+"t1"+c$+"6"
  2267.        DEFFN special.on$(n)=c$+"\"+CHR$(MOD(n,256))+CHR$(DIV(n,256))
  2268.        DEFFN ibm.special$(n)=c$+"^"+CHR$(n)
  2269.        DEFFN epson.special$(n)=ibm.set$+@ibm.special$(n)+epson.set$  
  2270.        '
  2271.        pica$=c$+"P"
  2272.        '
  2273.        elite$=c$+"M"
  2274.        '
  2275.        condensed.on$=CHR$(15)
  2276.        condensed.off$=CHR$(18)
  2277.        '
  2278.        large.on$=c$+"W1"
  2279.        large.off$=c$+"W0"
  2280.        large.line$=CHR$(14)
  2281.        '
  2282.        courier.proportional$=courier.style$+c$+"p1"
  2283.        prestige.proportional$=prestige.style$+c$+"p1"
  2284.        proportional.off$=c$+"p0"
  2285.        '
  2286.        DEFFN master.mode$(n)=c$+"!"+CHR$(n)
  2287.        underline=128
  2288.        italic=64
  2289.        expanded=32
  2290.        LET double.strike=16
  2291.        emphasized=8
  2292.        condensed=4
  2293.        proportional=2
  2294.        elite=1
  2295.        '
  2296.        normal.size$=c$+"h"+CHR$(0)
  2297.        LET double.size$=c$+"h"+CHR$(1)
  2298.        quad.size$=c$+"h"+CHR$(2)
  2299.        LET double.height$=c$+"w1"
  2300.        normal.height$=c$+"w0"
  2301.        normal.width$=f$+"E"+CHR$(0)
  2302.        LET double.width$=f$+"E"+CHR$(1)
  2303.        triple.width$=f$+"E"+CHR$(2)
  2304. Ç       '
  2305.        lf$=CHR$(10)
  2306.        DEFFN lf$(n)=c$+"f1"+CHR$(n)
  2307.        rev.lf$=c$+CHR$(10)
  2308.        '
  2309.        ff$=CHR$(12)
  2310.        rev.ff$=c$+CHR$(12)
  2311.        '
  2312.        justify.left$=c$+"a0"
  2313.        justify.right$=c$+"a2"
  2314.        justify.full$=c$+"a3"
  2315.        center$=c$+"a1"
  2316.        '
  2317.        reset$=c$+"@"
  2318.        '
  2319.      RETURN
  2320. Ofcourseyoucoulddeleteallvariablesyoudon'tneedinyourprogram.
  2321. Anditreallywouldbeniceifeveryoneusestheproposednames.Oneof
  2322. thestrongpointsofPublicDomainGFA-programsisthatit'seasytoadapt
  2323. aprogram.Orrather,itshouldbeeasy.UsingtheaboveProcedureisone
  2324. stepintherightdirection.
  2325.      
  2326.  
  2327. üë11.FILES
  2328. Ç
  2329.  
  2330. üFloppyWriteTestÇ
  2331.  
  2332. YouareadvisedtoswitchtheWriteVerifytestoff:
  2333.      SPOKE&H444,0       !testoff
  2334.      SPOKE&H444,1       !teston(default)
  2335. AccordingtoexpertslikeDaveSmallandBillWilkinsontheVerifytestis
  2336. acompletewasteofvaluabletimeifyouwritetoadisk.
  2337.  
  2338.  
  2339. üStepRateÇ
  2340.  
  2341. Youwillfindthecurrentstep-rateofyourdrivewith:
  2342.      PRINTDPEEK(&H440)
  2343. Thefollowingvaluesarepossible:
  2344.      0-6ms
  2345.      1-12ms
  2346.      2-2ms
  2347.      3-3ms(default)
  2348. Theoperatingsystemonlylooksatthisvalueafterareset(?).Foran
  2349. external5.25"-driveyouprobablyhavetouse12ms.
  2350.  
  2351.  
  2352. üRAM-disk
  2353. Ç
  2354. DriveDisoftenreservedforaRAM-disk.GFAwillrecognizeaRAM-disk
  2355. withDFREE(4)onlyifitwasalreadypresentatthetimetheinterpreter
  2356. wasloaded.
  2357.  
  2358. Afterswitchingoffyour1040STyoushouldwaitatleast15seconds
  2359. beforeswitchingonagain.OtherwiseanoldRAM-disk(orsomethingelsein
  2360. RAM,e.g.avirus...)maystillbepresentwhenyouswitchyourcomputer
  2361. onagain.
  2362.  
  2363. IfaRAM-diskisnotinstalledproperlyafterareset,thereasoncouldbe
  2364. hiddeninthedrivebit-tableat&H4C2.TheoldTOSdoesnotclearthis
  2365. tableandaRAM-diskcanonlybeinstalledasdriveDifbit3iscleared.
  2366. Bytheway,usedriveC(bit2)êonlyÇforaharddisk.
  2367.  
  2368.  
  2369. üDIR$()Ç
  2370.  
  2371. UseGEMDOS25(Dgetdrv)tofindthecurrentdriveandcombinethiswith
  2372. DIR$(drive)tofindthecurrentpath:
  2373.      drive=GEMDOS(25)         !drive0-15
  2374.      drive$=CHR$(65+drive)    !driveA-P
  2375.      p$=DIR$(drive+1)
  2376.      IFp$=""
  2377.      path$=drive$+":\"      !maindirectory
  2378.      ELSE
  2379.      path$=drive$+":"+p$+"\"
  2380.      ENDIF
  2381. ÇWithDIR$(0)you'llfindthepathoftheêcurrentÇdrive,notnecessarily
  2382. driveA.DIR$(1)returnsthepathofdriveA.GEMDOSremembersthelast
  2383. usedpathforallavailabledrives.SeealsotheStandardProcedure
  2384. Get.path.
  2385.  
  2386. IfyourunGFA-BasicfromthemaindirectoryandloadaGFA-programfroma
  2387. folder,DIR$(0)willreturnthenullstring(""),notthefolder.After
  2388. usingCHDIRwiththefolder-name,thecorrectpathwillbereturned.Iuse
  2389. CHDIRintheShell-programs,sotheStandardGlobaldefault.path$will
  2390. containthepathoftheGFA-program.Thismakeslifeeasierifyouwantto
  2391. loaddata-filesfromthesamefolder,butdon'tknowtheprecisepathwhen
  2392. youwritetheprogram.Itwouldbeniceifyoucoulddeterminethepathof
  2393. therunningGFA-programintheprogramitself.
  2394.  
  2395. Youcanmakeanarray-tableofavailabledriveswiththeaidofBIOS10
  2396. (Drvmap):
  2397.      DIMdrive!(15)
  2398.      SELECTDPEEK(&H4A6)
  2399.      CASE1
  2400.      drive!(0)=TRUE
  2401.      CASE2
  2402.      drive!(0)=TRUE
  2403.      drive!(1)=TRUE
  2404.      ENDSELECT
  2405.      table%=BIOS(10)
  2406.      FORn=2TO15
  2407.      IFBTST(table%,n)
  2408.      drive!(n)=TRUE
  2409.      ENDIF
  2410.      NEXTn
  2411.  
  2412. Youcancheckifaharddiskisconnectedwith:
  2413.      IFPEEK(&H472)<>0
  2414.      harddisk!=TRUE
  2415.      ENDIF
  2416.  
  2417.  
  2418. üDIRÇüandFILESÇ
  2419.  
  2420. AfterDIR,FILES,TRONorDUMPyoucanslowdownthescrollingwith
  2421. <CapsLock>.Youcantemporarilystopthescrollingbyholdingdownthe
  2422. right<Shift>-key.TheoutputafterDIRfitsonanyscreen,buttheFILES-
  2423. outputistoowideforLowresolution.DIRwillshowonlyêfilesÇinthe
  2424. currentdirectory.FILESwillalsoshowêfoldersÇ(markedwith*).WithDIR
  2425. (andFILESELECT)youwillnotbeabletosee"hidden"filesor"system"
  2426. files,butFILESwillshowallfiles.Youcanalsosearchforhidden
  2427. and/orsystemfileswithFSFIRSTandFSNEXTbysettingbit1and/orbit2
  2428. oftheattribute-byte.
  2429.  
  2430. PerhapsyouhavenoticedthatafterthecommandFILESthefirsttwolines
  2431. arepeculiarifyouhappentobeinafolder.Thefirst"name"inafolder
  2432. isalways'.'(onedot)andthesecondalways'..'(twodots).Timeand
  2433. dateareincorrect,becausetheauthorsof(theold)TOSforgottoconvert
  2434. thesetoMS-DOSformat.Incaseofnestedfolders,theoperatingsystem
  2435. Çfindstheprecedingfolderthroughapointerofthe'..'-file.That'swhy
  2436. youcanuse'CHDIR..'toreturntotheprecedingfolder.Don'ttrythis
  2437. inthemaindirectory,oryou'llgetanerror.
  2438.  
  2439.  
  2440. üFSFIRSTandFSNEXTÇ
  2441.  
  2442. TheDTA-bufferisusuallyfoundatBASEPAGE+128(it'salwaysthereafter
  2443. start-up),butyoushouldnotcountonit.UseFGETDTA()tofindthe
  2444. currentaddress,beforeFSFIRST:
  2445.      dta.adr%=FGETDTA()
  2446.      e%=FSFIRST(format$,attr)
  2447. FSFIRSTreturns-33ifnofilehasbeenfound.FSNEXTreturns-49ifno
  2448. morefilesarefound.
  2449.  
  2450. Inanaccessoryit'ssafertocreateanewDTA-buffer:
  2451.      old.dta%=FGETDTA()            !oldbuffer
  2452.      dta$=STRING$(44,0)
  2453.      dta.adr%=V:dta$               
  2454.      ~FSETDTA(dta.adr%)            !newbuffer
  2455.      (...)                         !FSFIRST/FSNEXT
  2456.      ~FSETDTA(old.dta%)            !restoreoldbuffer
  2457. TheDesktopwillappreciateallthisextrawork.
  2458.  
  2459. The44byteDTA-buffer(DataTransferAddress)containsthefollowingdata
  2460. afterasuccesfulFSFIRSTorFSNEXT:
  2461.      êoffsetÇ
  2462.      0-20     -reserved
  2463.      21     -attribute-byte
  2464.      22-23     -time
  2465.      24-25     -date
  2466.      26-29     -file-length
  2467.      30-43     -filename(includingtheextension,terminatedby&H00)
  2468. Theattributesandthefilenamecanbereadfromthebufferwith:
  2469.      attr=BYTE{dta.adr%+21}
  2470.      file$=CHAR{dta.adr%+30}
  2471.  
  2472. TheDTA-bufferisnotanexactcopyoftherelevantinformationinthe
  2473. directoryofthedisk.Withadisk-editoryouwouldfindaslotof32
  2474. bytesforeachfileorfolder:
  2475.      êoffset
  2476. Ç     0-7     -file-orfolder-name(withoutextension)
  2477.      8-10     -extension
  2478.      11     -attribute-byte
  2479.      12-21     -reserved
  2480.      22-23     -time
  2481.      24-25     -date
  2482.      26-27     -FAT-pointer
  2483.      28-31     -file-length
  2484. ÇThefirstbyteofthefilenamehasaspecialmeaninginthefollowing
  2485. cases:   
  2486.      &H00      -freeslot,neverusedbefore
  2487.      &HE5      -erasedfile,nowfreeslot
  2488.      &H2E      -subdirectory
  2489. BothtimeanddatearestoredinMS-DOSformat.ConsultyourGFA-manual
  2490. formoreinformation.TheFAT-pointer,alsoinanMS-DOSformat(Intel-
  2491. format :firstlowbyte,thenhighbyte),pointstothefirstclusterof
  2492. thefile.Ifyouarelookingatafolder,theFAT-pointerpointstothe
  2493. clusterwhereyouwillfindthedirectoryofthisfolder(subdirectory).
  2494. Ifyouarelookingatasubdirectory(i.e.youareêinÇafolder),thefirst
  2495. twoslotsarereservedforthefiles'.'and'..'(&H2Eand&H2E2E).This
  2496. hasalreadybeenmentionedintheparagraph'DIRandFILES'.Finally,the
  2497. file-lengthisstoredin,youguessedit,MS-DOSformat.Youmightwonder
  2498. whatMS-DOShastodowithAtari-disks.Readtheparagraphs'DiskFormat'
  2499. and'FileAllocationTable'fortheexplanation.
  2500.  
  2501. Ifyouusetheattribute-byte&X10000youwillfindbothfoldersêandÇ
  2502. files!Ifthefoldersinadirectorydon'thaveanextensionandallfiles
  2503. dohaveanextension,youcouldfindallfoldersinthemaindirectoryas
  2504. follows:
  2505.      e%=FSFIRST("\*",&X10000)      !ande%=FSNEXT()fornextfolders
  2506.  
  2507. Ifyoucan'tusethissimplemethod,you'llhavetocheckaftereach
  2508. successfulFSFIRST/FSNEXTifit'safolderorafile:
  2509.      IFBTST(BYTE{dta.adr%+21},4)
  2510.      (...)                       !yes,it'safolder
  2511.      ENDIF
  2512.  
  2513. Usetheattribute-byte0(i.e.nobitsset)tofindordinaryfilesonly.
  2514.  
  2515. Useattribute-byte&X1000tofindthedisk-name:
  2516.      dta.adr%=FGETDTA()
  2517.      e%=FSFIRST("\*.*",&X1000)     !findsdisk-nameonly,ênotÇfiles
  2518.      disk.name$=CHAR{dta.adr%+30}
  2519.  
  2520. YoucanreadtheattributesofafileorfolderwithGEMDOS67(Fattrib):
  2521.      attr%=GEMDOS(67,L:V:filename$,0,0) 
  2522. Ifthefile(orfolder)isnotfound,attr%is-33(or-34),otherwise
  2523. attr%containstheattributesintheusualformat.Youcanevenchangethe
  2524. attributesoffileswith:
  2525.      r%=GEMDOS(67,L:V:filename$,1,attribute%)
  2526. It'snotpossibletochangetheattributesoffoldersorthedisk-name
  2527. withGEMDOS67.Onewaytodothatistochangethedirectory-sectorwith
  2528. theaidofBIOS4(Rwabs).Ifyoureallyfeeltheurgetoexperiment,you
  2529. shouldrealizethatonetinymistakecouldruinthedisk.
  2530.  
  2531.  
  2532. üEXISTÇ
  2533.  
  2534. YoucanuseEXISTtotestifafolderexists,butonlyifthefolder
  2535. containsatleastonefile:
  2536.      IFEXIST("\FOLDER\*.*")
  2537.      (...)                 !folderfound
  2538.      ELSE
  2539.      (...)                  !foldernotfoundêorÇemptyfolder
  2540.      ENDIF
  2541.  
  2542.      
  2543. üLOFÇ
  2544.  
  2545. ThelengthofafileiseasilydeterminedwithLOF:
  2546.      OPEN"I",#1,file$
  2547.      length%=LOF(#1)
  2548.      CLOSE#1
  2549.  
  2550. Todeterminethenumberofrecordsinarandomfileyoucoulddividethe
  2551. file-lengthbythetotalFIELD-length.
  2552.  
  2553.  
  2554. üTOUCHÇ
  2555.  
  2556. UsethismethodwithTOUCH:
  2557.      OPEN"U",#1,file$
  2558.      TOUCH#1
  2559.      CLOSE#1
  2560.  
  2561.  
  2562. üNAMEÇ
  2563.  
  2564. WiththeoldTOSyoucanonlychangethenameoffiles,ênotÇoffolders.
  2565. Evenfromthedesktopyoucan'tchangethenameofafolder,sochooseit
  2566. carefully.
  2567.  
  2568.  
  2569. üKILLÇ
  2570.  
  2571. KILLingafiledoesnoteraseitfromthedisk.Thefirstbyteofthe
  2572. filenameischangedto&HE5.Unfortunatelyyoucan'trestoreakilledfile
  2573. bysimplychangingthisbytewithadisk-editor.Theoperatingsystemwill
  2574. beabletofindthefirstclusteroftherestoredfile,becausethefirst
  2575. FAT-pointerislocatedinthedirectory.Thenextclusterscanonlybe
  2576. foundthroughtheFAT(FileAllocationTable),butafterKILLallpointers
  2577. tothisfileareirreversiblyerased.Ifyouhavenotkilledanyfileon
  2578. thediskbeforeyourfatalmistake,youareextremelyluckyandwillfind
  2579. allclustershavebeenstoredconsecutively.Butaftersomekillingand
  2580. savingonthedisk,thefilecouldbedispersedovertheentiredisk.Some
  2581. programsareabletohelpyou,butyouwillhavetorecognizeclustersas
  2582. belongingtothekilledfile.That'seasywithASCII-files,butalmost
  2583. impossiblewithotherfiles.So,don'tKILLunlessyouhaveto.
  2584.  
  2585.  
  2586. üFileCopyÇ
  2587.  
  2588. Youcancopyafilesource$todest$(usecompletepathnames!)with:
  2589.      PROCEDURE file.copy(source$,dest$)
  2590.        LOCAL block%
  2591.        OPEN "I",#90,source$
  2592.        OPEN "O",#91,dest$
  2593.        block%=LOF(#90)
  2594.        WHILE block%>32000
  2595.          PRINT #91,INPUT$(32000,#90);
  2596.          SUB block%,32000
  2597.        WEND
  2598.        PRINT #91,INPUT$(block%,#90);
  2599.        CLOSE #90
  2600.        CLOSE #91
  2601.      RETURN
  2602.  
  2603. Donotcopyafile"toitself"onaharddisk.Thankstoyetanotherbugin
  2604. TOS,thisactioncouldcompletelywipeouttheharddisk.Orperhapsthis
  2605. shouldbecalledafeatureofTOS,puttheretopunishthecrazyuserwho
  2606. triestocopyafiletoitself.
  2607. ü
  2608.  
  2609. DiskFormatÇ
  2610.  
  2611. Adiskcontains80concentrictracks(numbered0-79)ormore.Sometimes
  2612. theexpression"cylinder"isusedinsteadof"track".Eachtrackis
  2613. dividedinto9,10oreven11sectors.Onesectorcancontain512data-
  2614. bytes.InordertobecompatiblewithMS-DOS,TOSformatsadiskwith80
  2615. tracksand9sectors/track.Actuallyit'seasytofit10sectorsinone
  2616. track.Withalittlemoreeffortyoucancreateroomfor11sectors,but
  2617. somedrivesrunslightlytoofastandarenotabletoreadthe11th
  2618. sector!
  2619.  
  2620. Withadisk-editoryoucanexaminethe512data-bytesofasector,but
  2621. youcan'texaminethesector-layoutwithoutaccessingtheFloppyDisk
  2622. Controller(FDC)directly.Inthatcaseyouwouldfindthefollowing
  2623. layoutforeachsector:
  2624.      data-separator(GAP)     -15bytes
  2625.      ID-Addressmark          -1byte
  2626.      sector-header            -4bytes(track,side,sector,size)
  2627.      CRCofsectorheader     -2bytes
  2628.      dataseparator           -37bytes
  2629.      Data-AddressMark        -1byte
  2630.      databytes               -512bytes
  2631.      CRCofdatabytes        -2bytes
  2632.      dataseparator           -40bytes
  2633. ThedataseparatorbytesaretheretosynchronizetheFDCproperly.The
  2634. FDCrecognizesthesector-headerbytheprecedingID-Addressmark.The
  2635. sector-headeritselfcontainsinformationaboutthecurrenttrack,side
  2636. andsectorandalsoaboutthesizeofthedata-field(usually512bytes).
  2637. TheFDCchecksboththesector-headerandthedata-fieldforcorrupted
  2638. bytesbycomparingacomputed"checksum"withthestoredCRC-value.The
  2639. operatingsystemcannotread/writeonebytefrom/toasector,only
  2640. Çcompletesectorsarereadorwritten.GFA-Basictakescareofallthe
  2641. dirtywork.
  2642.  
  2643. Firstsomebadnews.ACRC-errorisnotalwaysrecognizedbytheROMof
  2644. 520ST'sand1040ST's(buginXBIOS8,Floprd).Ifyourpalmsarenow
  2645. gettingsweatty,youcouldcheckyourmostpreciousdiskswithXBIOS19
  2646. (Flopver).Thisfunctionchecksfor'lostdata,RNF-orCRC-errors'.
  2647. Createabufferof1024bytesandcallXBIOS19.Asector(512bytes)is
  2648. loadedfromthediskindriveAorB(0or1)intothesecondpartofthe
  2649. bufferandchecked.Ifabadsectorisfound,thesector-numberisstored
  2650. asawordinthefirstpartofthebuffer.Aftercheckingallsectorsin
  2651. onetrackyouhavetoexaminetheword-listinthebuffer.Hopeyouwill
  2652. findonly&H0000there.Ileavethewritingofthisprogramasanexercise
  2653. tothereader.NeverthoughtIwouldusethatphrasemyself.Allright,
  2654. here'ssomethingtogetstarted:
  2655.      buffer$=STRING$(1024,0)
  2656.      adr%=V:buffer$
  2657.    r%=XBIOS(19,L:adr%,L:0,drive,1,track,side,9)  !if9sectors/track
  2658. Youshouldnowbeabletofindoutifthetrackonthisside(0or1)is
  2659. OK.Goodluck.
  2660.  
  2661. YoucanuseBIOS7(Getbpb)toexaminethedisk-formatintheso-called
  2662. BIOS-Parameter-Block(BPB)ofthedisk:
  2663.      bpb.adr%=BIOS(7,drive)   !addressofBPB,or0(=error)
  2664. In9wordsyou'llfindthefollowinginformationintheBPB:
  2665.      êoffsetÇ
  2666.      0      -bytes/sector(usually512)
  2667.      2      -sectors/cluster(usually2)
  2668.      4      -bytes/cluster
  2669.      6      -numberofdirectory-sectors
  2670.      8      -lengthofFAT
  2671.      10      -firstsectorofsecondFAT
  2672.      12      -firstdata-sector
  2673.      14      -totalclusters
  2674.      16      -flag(notused)
  2675.  
  2676. UseGEMDOS54(Dfree)tofindouthowmanyfreeclustersareavailable,or
  2677. simplyuseDFREEifyouwanttoknowhowmanyfreebytesareavailableon
  2678. adrive.Duetoabug,GEMDOSmissesthelasttwoclustersonadisk.You
  2679. can'twritetotheseclusters(2048bytesdownthedrain...),butyoucan
  2680. readtheseclustersiftheydocontaindata.Thatwouldbeamiracle,or
  2681. anMS-DOSdisk.
  2682.  
  2683. You'llprobablyuseXBIOS10(Flopfmt)toformatadiskfromGFA-Basic.If
  2684. youdo,use&H0000asthevirgin-valueforthefirst18sectors,andthen
  2685. &HE5E5foralldata-sectors.Youcanuseeither9or10sectors/track,not
  2686. 11.Ifyouuse10sectors/track,youshouldfillthefirsttwotrackswith
  2687. &H0000andfillsectors19and20with&HE5E5afterwards(readthe
  2688. paragraph'Sectors').Idon'trecommendmorethan80tracks,certainlynot
  2689. morethan82tracks.IfXBIOS10returnsavalueotherthan0,you'llfind
  2690. alistofbadsectorsinthebufferyouused(terminatedwith&H00).If
  2691. oneofthefirst18sectorsisbad,youcanthrowthediskaway.
  2692.  
  2693. ÇUsingXBIOS10,theinterleave-factorshouldbe1.Thismeansthesectors
  2694. onatrackarenumberedconsecutively:1,2,3,4,etc.Idon'tunderstand
  2695. whysomeprogrammersuseanothervalueandcallit'FastFormat'.TheFDC
  2696. needsmoretimetoreadacompletetrackiftheinterleave-factorisnot
  2697. 1.Perhapstheytrytocreatetheso-calledTwisted(orSkewed)format.
  2698. TOSlosestimeiftheheadmovestothenexttrack.BecausetheSeekwith
  2699. Verifyflagisset,theFDCfirstverifiesthetrack-numberandthenreads
  2700. thesector-number.Whilecheckingthetrack-number,sector1waspassing,
  2701. sowehavetowaitforonecompletespinofthedisk(200ms,yawn)until
  2702. sector1canberead.OnesolutionistocleartheSeekwithVerifyflag,
  2703. butthatcouldleadtonastyproblemsiftheheadstillrattlesslightly
  2704. atthetimesector1isread.ThebestsolutionistheTwistedformat
  2705. (adoptedbyAtarifromtheMegaSTonwards).Forasingle-sideddiskwith
  2706. 9sectorsononetrackthismeans:
  2707.      track0:sector1,2,3,4,5,6,7,8,9
  2708.      track1:sector8,9,1,2,3,4,5,6,7
  2709.      track2:sector6,7,8,9,1,2,3,4,5
  2710.      etc.
  2711. Now,sector1isencounteredalmostimmediatelyafterthetrack-numberis
  2712. verified.A1-sectoroffsetisnotpossible,buta2-sectoroffsetis
  2713. enoughtosettletherattlinghead.Itisimpossibletoreaddatafaster
  2714. fromadisk!ButI'mafraidyoucan'tformataTwisteddiskwithXBIOS10
  2715. ifyouhaveanoldTOS.Youhavetouseaspecialformat-program.
  2716.  
  2717. Ifyouformatadiskfromthedesktop,badclustersareflaggedwitha
  2718. specialvalueintheFAT.However,ifTOS1.4encountersabadsector,
  2719. somethinggoeswrongandtheFATiscorrupted.Onemorereasontoquit
  2720. smoking,becausesmoke-particlesdefinitelyconstituteaserioushazardto
  2721. thehealthofyourdisks.
  2722.  
  2723. YoucanuseXBIOS18(Protobt)tocreateabootsectorontheformatted
  2724. disk.Don'tworryaboutthemedia-byte(disk-type),becauseTOSdoesn't
  2725. useit.Douse&H1000000togeneratearandomserialnumber,becauseitis
  2726. êveryÇimportantthatdifferentdiskshavedifferentserialnumbers!Write
  2727. thebootsectortothediskwithXBIOS9(Flopwr),notwithBIOS4(Rwabs):
  2728.      r%=XBIOS(9,L:buffer%,L:0,drive%,1,0,0,1)
  2729.  
  2730. Whyaredifferentserialnumberssoimportant?IfTOSsuspectsadisk-
  2731. swap,theserialnumberisreadfromthedisk.Adisk-swapcanonlybe
  2732. recognizedifthenumberonthenewdiskisdifferentfromtheoldnumber.
  2733. Ifthenewdiskcontainsthesameserialnumber,TOSusestheFATofthe
  2734. previousdisk.Writingtoaswappeddiskwillprobablyzapit,ifyou
  2735. followme.Disk-copierscopyeverything,includingserialnumbers.Be
  2736. careful!
  2737.  
  2738. AlthoughitispossibletoformatadiskfromGFA-Basic,Idon'trecommend
  2739. it(nowhetellsus...).Myfavouriteformatis:
  2740.      80tracks
  2741.      10sectors/track
  2742.      Twistedformat
  2743. IuseTWISTER.PRG(notPublicDomain,asfarasIknow),butyoucoulduse
  2744. aPublicDomainprogramlikeDCOPY(actuallyShareware).TheDesktopcan't
  2745. copyaTwisteddisk,butfile-copyisalwayspossible.DCOPYcopiesany
  2746. format,includingTwistedformat.
  2747. üFileAllocationTable(FAT)
  2748. Ç
  2749. Thefirstsectoronadiskistheboot-sector.Thenextfivesectorsare
  2750. reservedfortheFAT.AndthenextfiveforacopyoftheFAT(actually
  2751. it'stheotherwayaround).Finally,themain(orroot)directoryoccupies
  2752. thenext7sectors(32bytesforeachslot).Thismeansthatthefirst18
  2753. sectors(No.0-17)arereservedfortheoperatingsystem.Allother
  2754. sectorsareavailableforstoringfiles.
  2755.  
  2756. Thestorage-unitforfilesisacluster.Aclusterconsistsoftwo
  2757. consecutivesectors(1024bytes).Afilethatcontainsonly1bytewill
  2758. thereforestilloccupy1024bytes(1K)onthedisk.Whenafileissaved,
  2759. theoperatingsystemlooksforthefirstemptycluster,thenthenext,
  2760. etc.InformationaboutavailableclustersisstoredintheFATasa
  2761. collectionofpointers.Duetoinefficientprogramming,thesearchfor
  2762. freeclusterstakesalongtime.TryDFREEonaharddiskandyou'llagree.
  2763. InstallaprogramlikeFATSPEED.PRG(PublicDomain,byUlrichKuebler)to
  2764. speedthisup!
  2765.  
  2766. ThefirstthreebytesoftheFATarenotusedbyTOS,butarethereto
  2767. enableMS-DOStoreadanST-formatteddisk.TOSwrites&HF7FFFF,wherethe
  2768. firstbyte(&HF7)issupposedtobethemedia-byte.UnfortunatelyMS-DOS
  2769. doesn'tunderstandthisandrefusestoreadthedirectoryproperly.I'm
  2770. notquitesurewhy,butchangingthefirstthreebytesto&H000000seems
  2771. towork.Youcouldtry&HF8FFFF(80tracks,9sectors/track,singlesided
  2772. disk)or&HF9FFFF(doublesideddisk)instead.Oryoucouldusethemedia-
  2773. byteatoffset21fromthebootsector.TomakeyourMS-DOSfriends
  2774. completelyhappy,youshouldchangethefirstthreebytesofthebootsec⑨
  2775. torto:&HEB3890.Sometimes(DOS4.0?)youhavetochangethenextthree
  2776. bytesaswell:&H49424D(that'sIBMinASCII;pleasewatchyourlanguage).
  2777. Betterstill,letthemusetheirowndiskeditorontheirMS-DOScomputer
  2778. (e.g.NortonUtilities).Whyshouldyoudoallthework?Bytheway,your
  2779. STshouldbeabletouseanMS-DOSdiskwithoutanymodifications.
  2780.  
  2781. EachFAT-pointerconsistsofoneandahalvebyte(3nibbles,i.e.12
  2782. bits).Inhexadecimalnotationthismeansthreedigitsforonepointer.
  2783. Thefirstpointer(No.0)pointstoclusterNo.0,thesecondtoNo.1,
  2784. etc..Becausethefirsttwopointersdon'tcount,youhavetosubtract
  2785. twotofindtheactualcluster(pointer2pointstoclusterNo.0,etc.).
  2786. ThefirstclusterstartsatsectorNo.18(remember,sectors0-17are
  2787. reservedforbookkeeping),soyoucouldfindthefirstsectorofacluster
  2788. with:
  2789.      (pointer-2)*2+18
  2790. Thesecondsectorofthisclusterisofcoursethenextone.
  2791.  
  2792. ÇTOSreadsthepointersinapeculiar(MS-DOS)way.SupposetheFAT-sector
  2793. startswith:
  2794.      F7FFFF034000FF0F00
  2795. Withoutfurtherexplanation,thistranslatesto:
  2796.      FAT-pointer0and1areignored
  2797.      FAT-pointer2=&H003(nextclusteronsector20+21)
  2798.      FAT-pointer3=&H004(nextclusteronsector22+23)
  2799.      FAT-pointer4=&HFFF(lastclusterofthisfile)
  2800.      FAT-pointer5=&H000(freecluster)
  2801. Inordertounderstandthis,youhavetoconsultthefollowingtable:
  2802.      &H000         :clusterstillavailable
  2803.      &HFF1-&HFF7:badcluster,neveravailable
  2804.      &HFF8-&HFFF:lastclusterofthisfile(EndOfFile)
  2805.      &H002-&HFF0:pointertonextcluster
  2806. AssumingtheFAT-pointer&H002atoffset26inthedirectory(you'llfind
  2807. &H0200withadiskeditor,that'sIntelformatwithêlowÇbytefirstagain),
  2808. youshouldbeabletofigureoutthatthisfilewillbefoundinsectors
  2809. 18through23.Sectors24/25areempty,sothisclusterisavailablefora
  2810. newfile.Anyquestions?Theonebigadvantageofallthisiscompatibi⑨
  2811. litywithMS-DOSdisks.WithTOS1.4yourST-diskscanbemadecompletely
  2812. compatible,soyoudon'tevenhavetochangeafewbytes.
  2813.  
  2814. Right,youhavejustreadtheFatman-book.Themoviewillbereleased
  2815. shortly,butyoucanNOWbuythosefabulousFatman-shirtsandfantastic
  2816. Fatman-buttons.CallAtariforfurtherdetails.
  2817.  
  2818.  
  2819. üSectorsÇ
  2820.  
  2821. Therearetwodifferentmethodstoassignanumbertoasector.Thefirst
  2822. oneistonumberthe"physical"sectorsineachtrackfrom1to9
  2823. (assuming9sectors/track).Thiswayyoucouldsaythebootsectoris
  2824. sector1ontrack0(onside0ifthediskisdoublesided).ButGEMDOS
  2825. doesn'tcareabouttracksorsides,itcounts"logical"sectorsfrom0to
  2826. 719(80tracks,9sectors/track,onesideddisk)orfrom0to1439(double
  2827. sideddisk).AccordingtoGEMDOS,thebootsectorisonsector0.Andona
  2828. doublesideddisk,physicalsector1ontrack0ofside1(theotherside)
  2829. wouldbesector9.
  2830.  
  2831. WithBIOS4(Rwabs)youcanread(andwrite)completeêlogicalÇsectors:
  2832.      buffer$=SPACE$(512)      !512bytesfor1sector
  2833.      buffer%=V:buffer$      !addressofbuffer
  2834.      r%=BIOS(4,0,L:buffer%,1,sector%,drive%)      !loadthesucker
  2835. YouwouldloadthebootsectorfromthediskindriveAwith:
  2836.      r%=BIOS(4,0,L:buffer%,1,0,0)
  2837. YoucanuseBIOS4notonlywithfloppydisks,butalsowithaharddisk
  2838. oraRAM-disk.Afterloadingasector,youcanreadonebytewith:
  2839.      b|=BYTE{buffer%+n}      !nfrom0to511
  2840. Youcanreadawordwith:
  2841.      w=WORD{buffer%+n}
  2842. ButonlyifthewordstartsatanêevenÇaddress.Otherwiseyouhavetouse:
  2843.      w=BYTE{buffer%+n+1}+256*BYTE{buffer%+n}
  2844. ÇIfnecessary,youcanspeedthisupbyusingthespecialintegercommands
  2845. foradditionandmultiplication.HowaboutthisPolishmonster:
  2846.      DEFFN word(adr%)=ADD(BYTE{SUCC(adr%)},MUL(256,BYTE{adr%}))
  2847. Thenyouwoulduse:
  2848.      w=@word(ADD(buffer%,n))     
  2849.  
  2850. IfyouuseBIOS4towriteasectorafterformattingadisk,youshould
  2851. use'3'asaflag(not'1'):
  2852.      r%=BIOS(4,3,L:buffer%,1,sector%,drive%)
  2853.  
  2854. YoucanalsoreadandwriteêphysicalÇsectorswithXBIOS8(Floprd)and
  2855. XBIOS9(Flopwr).Withthesecommandsyoucouldevenread/writeall
  2856. sectorsononetrack.Thisistheonlywaytoreadatrack,because
  2857. readingacompletetrackisimpossibleduetoabugintheFDC.
  2858.  
  2859. Ifyouswapadiskafterloading/writingasectoryoushouldbecareful.
  2860. TestingwithBIOS9(Mediach)youcouldêmissÇthedisk-swap.Thiscouldbe
  2861. fatal,becauseTOSusestheFAToftheotherdisk!Ithinkyoucoulduse
  2862. BIOS7(Getbpb)inmostcases,butusetheProcedureForce.mediachifin
  2863. doubt:
  2864.      PROCEDUREforce.mediach
  2865.      LOCALx$,old.vector%,a%
  2866.      x$=SPACE$(12)
  2867.      old.vector%=LPEEK(&H47E)
  2868.      a%=V:x$
  2869.      DPOKEa%,&H2B7C
  2870.      LPOKEa%+2,old.vector%
  2871.      DPOKEa%+6,&H47E
  2872.      DPOKEa%+8,&H7002
  2873.      DPOKEa%+10,&H4E75
  2874.      SLPOKE&H47E,a%
  2875.      ~DFREE(0)              !currentdrive
  2876.      RETURN
  2877. Tobemoreprecise,BIOS7can'tbeusedinthefollowingsituation:
  2878.      -TOSreadsasector
  2879.      -youswapdisks
  2880.      -youuseBIOS7inyourprogram
  2881.      -TOSreadsasector
  2882. NowTOSwillassumetherehasbeennodisk-swap,becausetherehasbeenno
  2883. disk-swapafterthelastBIOS7call!YoudefinitelyneedtheProcedure
  2884. Force.mediachinthiscase.
  2885.  
  2886. Bythetrack,TOSalsoignoresdisk-swapsduringascreendump(HARDCOPY),
  2887. orwhileusingDMA(harddisk,laserprinter).TOSdetectsadisk-swapby
  2888. monitoringthewrite-protectstate.Toseethis,youshouldturnall
  2889. lightsoffandthenwatchthedrive-lightclosely.Closer.Youcanturn
  2890. thelightsonagain.Ifthedriveisempty,TOSgetsawrite-protect
  2891. signalandassumestheusermighthaveswappeddisks.BIOS9shouldreturn
  2892. '1'atthispoint.TOSchecksifyoureallydidswapdisksbyreadingthe
  2893. serialnumberfromthebootsectorandcomparingitwiththecurrent
  2894. number.Onlyifthesenumbersaredifferent,adisk-swapisrecognizedby
  2895. TOS(BIOS9shouldreturn'2'now).YouprobablydeducedthatTOSwill
  2896. readthebootsectoralsoifyouuseawrite-protecteddisk.Continuously
  2897. readingthebootsectorisawasteoftime,soTOSwaits1.5secondsbefore
  2898. Çlookingagain.Neverswapdiskswithin1.5secondsafteraread/write-
  2899. operation.Thedrivekeepsspinningfor2seconds,soyoucan'tgowrong
  2900. ifyouwaituntilthedrive-lightisoffbeforeswappingdisks.
  2901.  
  2902. üBootsectorÇ
  2903.  
  2904. Inthefollowingtableyou'llfindthelay-outofabootsector.Allwords
  2905. areinIntel-format,exceptCHKSUM.
  2906.  
  2907.      êoffsetÇ    êlengthÇ    ênameÇ
  2908.  
  2909.      0      2                 &H6038=branchtobootroutine
  2910.      2       6       FILLER    fill-bytes
  2911.      8      3       SERIAL    serial-numberofdisk
  2912.  
  2913.      11      2       BPS       bytes/sector(512)
  2914.      13      1       SPC       sectors/cluster(2)
  2915.      14    2       RES       reservedsectors(1,Bootsector)
  2916.      16      1       NFATS     numberofFAT's(2)
  2917.      17      2       NDIRS     max.entriesinmaindirectory
  2918.      19      2       NSECTS    totalsectors
  2919.      21      1       MEDIA     media-byte(notusedbyTOS)
  2920.      22        2       SPF       sectors/FAT(5)
  2921.      24      2       SPT       sectors/track
  2922.      26      2       NSIDES    sides(1or2;nojokethistime)
  2923.      28      2       NHID      hiddensectors(ignoredbyTOS)
  2924.  
  2925.      30      2       EXECFLAG  startofbootcode:flag
  2926.      32      2       LDMODE    0=loadFNAME;<>0=loadsectors
  2927.      34      2       SSECT     firstsector(LDMODE<>0)
  2928.      36      2       SECTCNT   numberofsectors
  2929.      38      4       LDADDR    loadatthisRAM-address
  2930.      42      4       FATBUF    addressofFAT-buffer
  2931.      46      11       FNAME     filename(nnnnnnnneee)(LDMODE=0)
  2932.      57      1       DUMMY     fill-byte
  2933.  
  2934.      58                          boot-routine(couldbeaboot-virus)
  2935.  
  2936.      510      2       CHKSUM    
  2937.  
  2938. TOSdeterminesifthebootsectorisexecutablebyaddingallbytes.If
  2939. thissum(AND&HFFFF)equals&H1234,thebootsectorisexecutable.Ifyou
  2940. useGFA-BasicthisprobablymeansyouhaveanancientSTwithTOSinRAM,
  2941. oraboot-virus.AnormalGFA-diskhasonly&H00-or&HE5-bytesfromthe
  2942. offset58.
  2943.  
  2944.  
  2945. üBLOADÇ
  2946.  
  2947. BLOADneedsanaddress,unlessyouhaveusedBSAVEinthesameprogram
  2948. before.InthatcasetheBSAVE-addressisusedautomaticallybyBLOADif
  2949. youdon'tspecifyanewaddress.
  2950.  
  2951. ÇBLOAD(BSAVE)iseasiertousethanBGET(BPUT),becauseyoudon'thaveto
  2952. openthefile.ButwithBLOADyoucanonlyloadtheentirefile,while
  2953. BGETallowsyoutoloadanypartofthefile.
  2954.  
  2955.  
  2956. üINPandOUTÇ
  2957.  
  2958. BothINPandOUTcanalsobeusedwith2-byteand4-byteintegers:
  2959.      a|=INP(#n)
  2960.      a&=INP&(#n)
  2961.      a%=INP%(#n)
  2962.      OUT#n,a|
  2963.      OUT&#n,a&
  2964.      OUT%#n,a%
  2965.  
  2966.  
  2967. üINPUTandLINEINPUTÇ
  2968.  
  2969. BecauseGFAnowusesa4K-bufferforeachopenedfile(version3.07),
  2970. readingdatafromafilewith(LINE)INPUTgoesmuchfaster.
  2971.  
  2972.  
  2973. üSTOREandRECALLÇ
  2974.  
  2975. Forveryfastloadingandsavingofstring-arrays,youshoulduseRECALL
  2976. andSTORE.Youcanalsostore(orrecall)apartofanarrayasfollows:
  2977.      STORE#1,txt$(),10       !storeelements0through9
  2978.      STORE#1,txt$(),5TO10  !storeelements5through10
  2979.  
  2980. Thecorrectsyntaxis:
  2981.      STORE#i,x$()[,n[TOm]]
  2982.      RECALL#i,x$(),n[TOm],x%    (usen=-1forcompletearray)
  2983. Ofcourseyouhavetoopenthefilefirst.
  2984.  
  2985. IfyouSTOREatext-array,GFAputs&H0D0A(CHR$(13);CHR$(10))aftereach
  2986. element.Thisisthesameformatasusedby1stWordPlus(WPModeoff,
  2987. i.e.ASCII-mode),Tempus,etc.
  2988.  
  2989. Ifyou'regoingtoshowmorethanafewtext-lines,youcouldenterthe
  2990. textasDATA-lines,e.g.withtheProceduresInitio.text.arrayand
  2991. Initio.text.array.low(forLowresolution):
  2992.      PROCEDURE initio.text.array
  2993.        ' *** global :  TEXT$()
  2994.        LOCAL lines,line$,n
  2995.        lines=0
  2996.        RESTORE txt.data
  2997.        READ line$
  2998.        REPEAT
  2999.          INC lines
  3000.      READ line$
  3001.        UNTIL line$="***"
  3002. Ç       ERASE text$()
  3003.        DIM text$(lines)
  3004.        RESTORE txt.data
  3005.        FOR n=1 TO lines
  3006.          READ text$
  3007.          text$(n)=SPACE$(5)+text$           ! left margin of 5 spaces !!
  3008.        NEXT n
  3009.        txt.data:
  3010.      DATAtext
  3011.        DATA ***
  3012.      RETURN
  3013.  
  3014. Ifyouaregoingtoshowmoretext,Isuggestyouuse1stWordPlus,or
  3015. anyotherwordprocessorortext-editorthatcansaveyourtextasan
  3016. ASCII-file.With1stWordPlus,IuseaRulerlengthof70andthe
  3017. followingPageLayoutForm:
  3018.      Paperlength   66
  3019.      TOFmargin     19
  3020.      Headmargin    4
  3021.      Footmargin    4
  3022.      BOFmargin     19
  3023.      Lines/page     20
  3024. EnterthetextandsaveasanASCII-file(turnWPModeoffbeforesaving).
  3025. InyourGFA-Basicprogramyouwouldfirstloadthetextinastring-array:
  3026.      DIMtext$(lines)
  3027.      OPEN"I",#1,file$
  3028.      RECALL#1,text$(),-1,lines%!lines%≤lines+1
  3029.      CLOSE#1
  3030. ThenyoucouldusetheProcedureShow.text.page(HighorMediumresolu⑨
  3031. tion)toshowthetextwith20lines/screen.TheProcedureusesaleftand
  3032. rightmarginof5characters,sothat'swhyyouhavetouse70charac⑨
  3033. ters/lineinyourwordprocessor.Ifthetext-arrayisfull,youwon'tget
  3034. anerrorifthefilecontainsmoretext-lines!
  3035.  
  3036. Youcouldusea2-dimensionalstring-arraytostorefirstandlastnames:
  3037.      name$(i,0)=first_name$
  3038.      name$(i,1)=last_name$
  3039. Again,STOREandRECALLareveryfast.Butitisnownecessarytouse
  3040. exactlythesamedimensionswithRECALLthatyouusedwithSTORE.Ifthe
  3041. dimensionsdon'tmatch,thearraywillbescrambledafterRECALL.
  3042.  
  3043.  
  3044. üFILESELECTÇ
  3045.  
  3046. Don'tusetheunderscore'_'inthepath-lineoftheFileselector,because
  3047. abugintheoldTOSwillthencauseafewbombs.OwnersofaMegaSTor
  3048. TOS-version1.4canuseasmanyunderscoresastheylike.
  3049.  
  3050. ChangingdrivesintheFileselector(oldTOS)isnoteasy.Clickonthe
  3051. path-lineandpress<Esc>tocleartheline.Enterthedrive,e.g.'D:\',
  3052. andclickêonÇthebarunderthepath-lineinordertoreadthenew
  3053. directory.Alsoclickonthisbarafterchangingdisks(inthiscaseyou
  3054. wouldpress<Esc>onthedesktop).SelectingdriveAiseasier:justclear
  3055. thepath-lineandclickonthebar.TheTOS-codethattakescareofall
  3056. Çthisworkisalsoknownasthebartender.
  3057.  
  3058. Ifyouhavechangedtheextensioninthepath-line,youshouldclickêjust
  3059. belowÇthebar.IfyouclickêonÇthebar,thepath-lineisoverwrittenwith
  3060. '*.*'!Thatsamebartenderstrikesagain.
  3061.  
  3062. ThecorrectsyntaxforcallingtheFileselectoris:
  3063.      FILESELECT[#title$,]path$,default$,file$
  3064. ThetitleisonlyusedinTOS-version1.4andignoredinolderTOS-
  3065. versions.Thedefault$usuallyisthenull-string(""),butdon'tusethe
  3066. null-stringforpath$ortheFileselectorwillfreeze.Use"\*.*"aspath$
  3067. forallfilesinthemaindirectory.Dousethebackslashinthepathname
  3068. (e.g."A:\*.*").DuetoabuginGEM,thewrongdriveissometimesusedif
  3069. youforgetthebackslash("A:*.*").Iftheuserhasselectedafile,file$
  3070. willcontainthepathandfilename.Thefile$willbethenull-stringif
  3071. theuserselected<Cancel>.Athirdpossibilityiseasilyoverlooked:the
  3072. usercouldhaveselected<OK>withoutchoosingafile.Inthatcasefile$
  3073. containsthecurrentpath,endingwithabackslash.
  3074.  
  3075. Donotdespairifyouneedatitle,butdon'thaveTOS1.4.Trythe
  3076. ProcedureFileselect(HighorMediumresolution)orFileselect.low:
  3077.      PROCEDURE fileselect(path$,default$,txt$,left$,right$,VAR file$)
  3078.        ' *** print optional title (light text) to left and right 
  3079.        LOCAL screen$,y.fac
  3080.        SGET screen$          
  3081.        CLS
  3082.        IF high.res!
  3083.          y.fac=1
  3084.        ELSE
  3085.          y.fac=2
  3086.        ENDIF
  3087.        DEFTEXT black,2,900,32
  3088.        TEXT 100,350/y.fac,300/y.fac,left$
  3089.        DEFTEXT ,,2700
  3090.        TEXT 540,50/y.fac,300/y.fac,right$
  3091.        DEFTEXT ,0,0,13
  3092.        PRINT AT(1,3);@center$(txt$)
  3093.        GRAPHMODE 3
  3094.        DEFFILL black,1 
  3095.        BOUNDARY 0
  3096.        IF high.res!
  3097.          BOX 157,25,482,54
  3098.          PLOT 157,25
  3099.          PBOX 159,27,480,52
  3100.        ELSE
  3101.          BOX 157,12,482,27
  3102.          PLOT 157,12
  3103.          PBOX 160,14,479,24
  3104.        ENDIF
  3105.        BOUNDARY 1
  3106.        GRAPHMODE 1
  3107.        FILESELECT path$,default$,file$
  3108.        SPUT screen$
  3109.      RETURN
  3110. ÇAsaprogrammer,youshouldtakeintoaccountthepossibilitythatauser
  3111. mightstartyourprogramfromdriveA,aharddiskoraRAM-disk.Iusethe
  3112. StandardGlobaldefault.path$torememberwheretheprogramwasstarted.
  3113. Iftheuserchangesthe(default)pathintheFileselector,youshould
  3114. notethechangeandusethenewpathiftheFileselectoriscalledagain.
  3115. UsetheProcedureParse.filenameforthispurpose:
  3116.      PROCEDURE parse.filename(parse.name$,VAR drive$,path$,file$,ext$)
  3117.        LOCAL pos,first,last,last!,search,parse.file$
  3118.        '
  3119.        parse.name$=UPPER$(parse.name$)
  3120.        IF MID$(parse.name$,2,1)=":"
  3121.          drive$=LEFT$(parse.name$,1)
  3122.        ELSE
  3123.          drive$=CHR$(65+GEMDOS(&H19))    ! current drive
  3124.        ENDIF
  3125.        '
  3126.        pos=1
  3127.        last!=FALSE
  3128.        last=0
  3129.        first=INSTR(1,parse.name$,"\")
  3130.        REPEAT
  3131.          search=INSTR(pos,parse.name$,"\")
  3132.          IF search>0
  3133.            pos=search+1
  3134.            last=search
  3135.          ELSE
  3136.            last!=TRUE
  3137.          ENDIF
  3138.        UNTIL last!
  3139.        IF last>0                              ! backslash discovered
  3140.          path$=MID$(parse.name$,first,last-first+1)
  3141.          parse.file$=MID$(parse.name$,last+1)
  3142.        ELSE                                   ! no '\'
  3143.          path$=""
  3144.          pos=INSTR(1,parse.name$,":")
  3145.          IF pos>0
  3146.            parse.file$=MID$(parse.name$,pos+1)
  3147.          ELSE
  3148.            parse.file$=parse.name$
  3149.          ENDIF
  3150.        ENDIF
  3151.        pos=INSTR(parse.file$,".")
  3152.        IF pos>0                               ! name with extension
  3153.          ext$=MID$(parse.file$,pos+1)
  3154.          file$=LEFT$(parse.file$,pos-1)
  3155.        ELSE                                   ! name without extension
  3156.          ext$=""
  3157.          file$=parse.file$
  3158.        ENDIF
  3159.      RETURN
  3160.  
  3161. IfyouhaveajoystickwithAuto-Fireon,youshouldswitchitoff.The
  3162. Fileselectordoesn'tlikeAuto-Fire.NeitherdoI.
  3163.  
  3164. ÇTheFileselectorwillwarnyouwithamodest'ping'ifitcountsmorethan
  3165. 100files/folders.Itwillshowonlytheêfirst100Çfiles/folders.Ithink
  3166. 45filesinonefolderisreallythelimitforimpatientuserslike
  3167. myself.Morethan100isacrimethatshouldbepunishedwithmorethana
  3168. 'ping'.ThemaindirectoryofdriveAcan'tcontainmorethan112
  3169. files/folders,becausethe7directory-sectorscontain11232-byteslots.
  3170.  
  3171. Everytimeyouopenafolder(intheFileselector,orotherwise),TOS
  3172. storesinformationaboutthefolderinatable.Afteropening/accessing40
  3173. folders,TOSwilldeleteclusters,cross-linkclusters,anddoothernasty
  3174. things.Yourdiskcouldbecompletelydestroyed,thankstothisbug.Atari
  3175. enlargedthebufferinTOS1.2andfixedthebuginTOS1.4.Atarialso
  3176. distributestheprogramFOLDRxxx.PRGtoextendthe40-folderlimitwith
  3177. 100(FOLDR100.PRG)ormore.BecarefulwithSHOWINFO,it'seasytoexceed
  3178. the40-folderlimit!Youcouldrecognizeadisasterbyoneofthe
  3179. followingsymptoms:
  3180.      -unexpected'0bytesin0items'messageindirectory
  3181.      -folder-namestrashed(usuallylotsofGreekletters)
  3182.      -ShowInfocrashesorshowsweirdinformation
  3183. Don'tbeafraidofanewvirus.It'sonlyaTOS-bug.Immediatelyreset
  3184. yourST,trytosalvageasmanyfilesaspossibleandreformatthedisk.
  3185. Ifallfilesarelost,youwillhavetouseyourback-upfiles.Ifyou
  3186. don'thaveback-upfiles,youhavenothingleftbutmysympathy.
  3187.  
  3188.  
  3189. üë12.MIDI
  3190. Ç
  3191.  
  3192. üINPMID$Ç
  3193.  
  3194. WiththecommandINPMID$theinternalMidi-bufferisreadandatthesame
  3195. timecleared.YoucanfindthebufferwithXBIOS14(Iorec):
  3196.      adr%=LPEEK(XBIOS(14,2))
  3197. Thedefaultsizeofthisbufferisonly128bytes,butyoucanusethe
  3198. ProcedureChange.midi.buffertochangethesizeofthebuffer:
  3199.      PROCEDURE change.midi.buffer(size%)
  3200.        LOCAL ptr%
  3201.        ptr%=XBIOS(14,2)
  3202.        ERASE buffer|()
  3203.        DIM buffer|(size%-1)
  3204.        LPOKE ptr%,VARPTR(buffer|(0))   ! start-address ofnew buffer
  3205.        DPOKE ptr%+4,size%              ! size
  3206.        DPOKE ptr%+6,0                  ! buffer-head
  3207.        DPOKE ptr%+8,0                  ! buffer-tail
  3208.        DPOKE ptr%+10,0                 ! low mark (not used)
  3209.        DPOKE ptr%+12,size%-1           ! high mark (not used)
  3210.      RETURN
  3211. BecausehandshakeisimpossiblewithMidi,youneedalargebufferif
  3212. Midi-bytesarecominginfast.
  3213.  
  3214.  
  3215. üINPÇ
  3216.  
  3217. IfyouuseINP(3)toreadMidi-bytes,youshouldfirstcheckwithINP?(3)
  3218. iftheMidi-buffercontainsdata.IfyouuseINP(3)andnobytesare
  3219. available,yourSTwillfreeze.Untilyouresetthecomputer.
  3220.  
  3221.  
  3222. üMidi-commandsÇ
  3223.  
  3224. StudytheProceduresinthefileMIDI.LSTtoseehowyoucanuseMidi-
  3225. commandsinGFA-Basic.WiththeProceduresRecord.midiandPlay.midiyou
  3226. couldwriteasimpleMidi-recorder.AndtheProcedureMidi.monitorcanbe
  3227. usedtoexamineincomingMidi-messages.
  3228.      PROCEDURE record.midi(VAR midi.byte|(),midi.time%())
  3229.        ' *** uses Procedure All.midi.off
  3230.        ' *** global :  LAST.MIDI.BYTE%
  3231.        LOCAL last%,buffer$,i%,t%,time%,byte|,delay%,j%,m$,k
  3232.        ARRAYFILL midi.byte|(),0
  3233.        ARRAYFILL midi.time%(),0
  3234.        last%=DIM?(midi.byte|())-1
  3235.        m$=STR$(last%)+" bytes available ;| |stop recording|"
  3236.        m$=m$+"by pressing space"
  3237.        ALERT 3,m$,1,"RECORD",k
  3238.        REPEAT
  3239.        UNTIL INKEY$=""
  3240.        buffer$=INPMID$         ! clear MIDI-buffer
  3241.        i%=1
  3242.        t%=TIMER
  3243. Ç       REPEAT
  3244.          IF INP?(3)
  3245.            byte|=INP(3)
  3246.            IF byte|<>254
  3247.              time%=SUB(TIMER,t%)
  3248.              midi.byte|(i%)=byte|
  3249.              midi.time%(i%)=time%
  3250.              INC i%
  3251.           ENDIF
  3252.          ENDIF
  3253.        UNTIL i%=last% OR INKEY$=" "
  3254.        last.midi.byte%=i%-1
  3255.        @all.midi.off
  3256.        delay%=midi.time%(1)               ! subtract time for first note
  3257.        FOR j%=1 TO i%
  3258.          SUB midi.time%(j%),delay%
  3259.        NEXT j%
  3260.        m$="|"+STR$(i%)+" bytes recorded"
  3261.        ALERT 3,m$,1," OK ",k
  3262.      RETURN
  3263.      '
  3264.      PROCEDURE play.midi(VAR midi.byte|(),midi.time%())
  3265.        ' *** uses Procedure All.midi.off
  3266.        LOCAL m$,k,i%,t%,time%
  3267.        m$="record of "+STR$(INT(midi.time%(last.midi.byte%)/200))+
  3268.        m$=m$+" seconds| |(stop by pressing space)"
  3269.        ALERT 3,m$,1,"PLAY",k
  3270.        REPEAT
  3271.        UNTIL INKEY$=""
  3272.        i%=1
  3273.        t%=TIMER
  3274.        REPEAT
  3275.          time%=SUB(TIMER,t%)
  3276.          IF midi.time%(i%)<=time%
  3277.            OUT 3,midi.byte|(i%)
  3278.            INC i%
  3279.          ENDIF
  3280.        UNTIL i%=last.midi.byte% OR INKEY$=" "
  3281.        @all.midi.off
  3282.      RETURN
  3283.      '
  3284.      PROCEDURE midi.monitor
  3285.        LOCAL m$,k,byte|,byte$,hex$,bin$,buffer$,key$
  3286.        byte$=SPACE$(3)
  3287.        hex$=SPACE$(2)
  3288.        bin$=SPACE$(8)
  3289.        m$="all incoming bytes|(except 254) are|printed on screen ;|"
  3290.        m$=m$+"stop by pressing space"
  3291.        ALERT 1,m$,1,"START",k
  3292.        m$="press|<Return>|for CLS"
  3293.        ALERT 1,m$,1," OK ",k
  3294.        REPEAT
  3295.        UNTIL INKEY$=""
  3296. Ç       buffer$=INPMID$      ! clear MIDI-buffer
  3297.        CLS
  3298.        PRINT TAB(10);"dec";TAB(20);"hex";TAB(30);"binary"
  3299.        REPEAT
  3300.           REPEAT
  3301.            key$=INKEY$
  3302.            IF INP?(3)
  3303.              byte|=INP(3)
  3304.              IF byte|<>254
  3305.                IF TIMER-t%>200
  3306.                  PRINT
  3307.                ENDIF
  3308.                t%=TIMER
  3309.                RSET byte$=STR$(byte|)
  3310.                RSET hex$=HEX$(byte|)
  3311.                RSET bin$=BIN$(byte|)
  3312.                PRINT TAB(10);byte$;TAB(20);hex$;TAB(30);bin$
  3313.              ENDIF
  3314.            ENDIF
  3315.          UNTIL key$=" " OR key$=CHR$(13)
  3316.          IF key$=CHR$(13)
  3317.            CLS
  3318.          ENDIF
  3319.        UNTIL key$=" "
  3320.        @all.midi.off
  3321.        REPEAT
  3322.        UNTIL INKEY$=""
  3323.        PRINT " (press any key)"
  3324.        ~INP(2)
  3325.      RETURN
  3326.  
  3327.  
  3328. üë13.MODEM
  3329. Ç
  3330.  
  3331. üINPAUX$
  3332.  
  3333. ÇWiththecommandINPAUX$theinternalRS232-bufferisreadandatthesame
  3334. timecleared.Youcanfindtheaddressoftheinput-bufferwith:
  3335.      adr.in%=LPEEK(XBIOS(14,0))
  3336. Theoutput-buffercanbelocatedwith:
  3337.      adr.out%=LPEEK(XBIOS(14,0)+14)
  3338.  
  3339.  
  3340. üINPÇ
  3341.  
  3342. IfyouuseINP(1)toreadincomingbytes,youshouldalwayscheckwith
  3343. INP?(1)iftheRS232-buffercontainsdata.
  3344.  
  3345.  
  3346. üRsconf(XBIOS15)Ç
  3347.  
  3348. WithXBIOS15(Rsconf)youcanchangetheRS232-parameters.Afew
  3349. baudrates:
  3350.      0-19200baud
  3351.      1-9600baud
  3352.      4-2400baud
  3353.      7-1200baud
  3354.      9-300baud
  3355.     14-75baud
  3356. Use-1forparametersyoudon'twanttochange.DuetoaTOS-bug,you
  3357. can'tuse75baud,because'14'resultsin120baud.Also,theoldTOS
  3358. (pre-Blitterage)can'thandlehardwarehandshakewithRTS/CTS-signals.
  3359. Atarihasreleasedabug-fixthatshouldenableanyTOStouseRTS/CTS.
  3360. Softwarehandshaking(XON/XOFF)functionsproperly.Thedefault
  3361. afterpower-up isnohandshakeprotocol.
  3362.  
  3363.  
  3364. üë14.MOUSE
  3365. Ç
  3366.  
  3367. üEditorÇ
  3368.  
  3369. Sometimestheeditorseemstofreezewhilethecursorisblinkingrapidly.
  3370. Justmovethemouseandtheeditorcomesaliveagain.
  3371.  
  3372.  
  3373. üFileselector
  3374.  
  3375. ÇSometimesthesameblinkingmouseappearsaftercallingtheFileselector
  3376. oranAlert-box.I'vereadsomewherethiscouldbeduetothecombination
  3377. ofaVDI-function(forthemouse)andanAES-function(forFileselectoror
  3378. Alert-box).GFAtakescareofthefirstandGEMofthesecond,and
  3379. sometimesthisseemstoresultinaconflict.
  3380.  
  3381.  
  3382. üMOUSEÇ
  3383.  
  3384. IfyourepeatedlycallaProcedureinwhichyoutestforamouse-click,
  3385. youshouldincorporateashortpauseintheProcedure(e.g.PAUSE5).
  3386. OtherwisetheProceduremightbecalledagainwhiletheuserisstill
  3387. holdingthebuttondown.Youcouldalsowaituntiltheuserreleasesthe
  3388. button:
  3389.      REPEAT
  3390.      UNTILMOUSEK=0      !waituntilbuttonisreleased
  3391.  
  3392. Ifyoufinditdifficulttomovethemouseaccurately,youcoulduse
  3393. <Shift><Alternate><arrow>tomovethemouse-cursoronepixelinthe
  3394. desireddirection.Ifyoupress<Insert>aswell,youcan"drag"something
  3395. accuratelyasiftheleftmouse-buttonwaspressed.
  3396.  
  3397. Youcanfindthemaximalx-andy-coordinatesofthemousewith:
  3398.      x=DPEEK(&H9862)
  3399.      y=DPEEK(&H9864)
  3400. Butthere'snoguarantyyouwillfindthecoordinatesthere.Experiment
  3401. withXBIOS0foramorereliablemethod.Don'taskmehow.
  3402.  
  3403. MOUSEreturnsnegativecoordinatesifthemouseistotheleftoforabove
  3404. thecurrentwindow(ortheoriginthathasbeenselectedwithCLIP
  3405. OFFSET).
  3406.  
  3407.  
  3408. üSETMOUSEÇ
  3409.  
  3410. Amouseclickcanbesimulatedwith:
  3411.      SETMOUSEmx,my,mk
  3412. IfyoutrythiswithanAlert-buttonyouhavetomovethemouseafter-
  3413. wards,orthebuttonwon'tbeselected.Idon'tknowwhy,soIcan'ttell
  3414. ifthisisabug.
  3415.  
  3416.  
  3417. üDEFMOUSEÇ
  3418.  
  3419. YoucanuseoneofthemanyPublicDomainmouse-editorstodesignyourown
  3420. mouse-mutant.Butit'salsoeasytocreateanewmouse-cursorwiththe
  3421. ProcedureInitio.mouse1:
  3422.      PROCEDURE initio.mouse1
  3423.        ' *** global :  MOUSE1$
  3424.        RESTORE pattern.mouse1
  3425.        @make.mouse(mouse1$)
  3426.        pattern.mouse1:
  3427.        ' *** x,y,mode(0=normal;1=XOR),mask-colour,mouse-colour
  3428.        DATA 0,0,0,0,1
  3429.        ' *** mask-pattern (1 = pixel on , 0 = pixel off)
  3430.        DATA 0000000000000000
  3431.        DATA 0000000000000000
  3432.        DATA 0000000000000000
  3433.        DATA 0000000000000000
  3434.        DATA 0000000000000000
  3435.        DATA 0000000000000000
  3436.        DATA 0000000000000000
  3437.        DATA 0000000000000000
  3438.        DATA 0000000000000000
  3439.        DATA 0000000000000000
  3440.        DATA 0000000000000000
  3441.        DATA 0000000000000000
  3442.        DATA 0000000000000000
  3443.        DATA 0000000000000000
  3444.        DATA 0000000000000000
  3445.        DATA 0000000000000000
  3446.        ' *** mouse-pattern
  3447.        DATA 0000000000000000
  3448.        DATA 0000000000000000
  3449.        DATA 0000000000000000
  3450.        DATA 0000000000000000
  3451.        DATA 0000000000000000
  3452.        DATA 0000000000000000
  3453.        DATA 0000000000000000
  3454.        DATA 0000000000000000
  3455.        DATA 0000000000000000
  3456.        DATA 0000000000000000
  3457.        DATA 0000000000000000
  3458.        DATA 0000000000000000
  3459.        DATA 0000000000000000
  3460.        DATA 0000000000000000
  3461.        DATA 0000000000000000
  3462.        DATA 0000000000000000
  3463.      RETURN
  3464.      ' 
  3465. Ç     PROCEDURE make.mouse(VAR m$)
  3466.        LOCAL x,y,mode,msk.color,mouse.color,n,msk%,mouse%,msk.pat$
  3467.        LOCAL mouse.pat$,msk$,mouse$,pat$
  3468.        CLR msk.pat$,mouse.pat$,pat$
  3469.        READ x,y,mode,msk.color,mouse.color
  3470.        FOR n=1 TO 16
  3471.          READ msk$
  3472.         msk%=VAL("&X"+msk$)
  3473.         msk.pat$=msk.pat$+MKI$(msk%)
  3474.        NEXT n
  3475.        FOR n=1 TO 16
  3476.          READ mouse$
  3477.          LET mouse%=VAL("&X"+mouse$)
  3478.          LET mouse.pat$=mouse.pat$+MKI$(mouse%)
  3479.        NEXT n
  3480.        m$=MKI$(x)+MKI$(y)+MKI$(mode)+MKI$(color.index(msk.color))
  3481.        m$=m$+MKI$(color.index(mouse.color))+msk.pat$+mouse.pat$
  3482.      RETURN
  3483. Themaskshouldbeanexactcopyofthemouse-patternifyouneeda
  3484. transparantmouse.Leavethemaskempty(all'0')andthemousewill
  3485. disappearbehindobjectsonthescreen.Fillthemaskwith'1'andthe
  3486. 16x16mousewillalwaysremainvisible.Switchmask-andmouse-colourin
  3487. thefirstDATA-linetocreatea"reverse"mouse.OruseanyVDIcolour-
  3488. indexthatisavailableinthecurrentresolution.
  3489.  
  3490.  
  3491. üë15.JOYSTICK
  3492. Ç
  3493.  
  3494. üSTRIGandSTICKÇ
  3495.  
  3496. HereisanexampleoftheuseofSTRIGandSTICKifyourjoystickis
  3497. connectedtoPort1(yourmouseisconnectedtoPort0):
  3498.      STICK1             !joystick-mode(yourmouseisnowdead)
  3499.      REPEAT
  3500.      IFSTRIG(1)
  3501.      joy=3
  3502.      ELSE
  3503.      joy=STICK(1)
  3504.      ENDIF
  3505.      ONjoyGOSUBn,s,fire,w,nw,sw,dummy,e,ne,se
  3506.      PAUSE5
  3507.      (...)
  3508.      UNTILcondition!
  3509.      STICK0             !backtomouse-mode
  3510. YouneedeightProceduresfortheeightpossibledirections(seebelow)
  3511. andoneProcedurefortheFire-button.Thevalue7('dummy')neveroccurs.
  3512. Ifyoudon'ttouchthejoystick,thevalueof'joy'willbe0,andthis
  3513. meansnoProcedurewillbecalled.Ashortpauseisadvisable,because
  3514. GFA-Basicistoofast.
  3515.                    519
  3516.                     \|/
  3517. directions:       4-0-8
  3518.                     /|\
  3519.                     6210
  3520.  
  3521. Ifyoudesperatelyneedanactivemousewhileusingthejoystick,you
  3522. couldtrythefollowing"dirty"method:
  3523.      REPEAT
  3524.        IF MOUSEK=2
  3525.          joy=3
  3526.        ELSE
  3527.          joy=BYTE{&HE09}        ! forTOS-version1.0!!
  3528.        ENDIF 
  3529.        ON joy GOSUB n,s,fire,w,nw,sw,dummy,e,ne,se
  3530.        PAUSE 5  
  3531.      UNTILcondition!
  3532.  
  3533.  
  3534. üë16.SOUND
  3535. Ç
  3536.  
  3537. üSOUNDÇüandWAVEÇ
  3538.  
  3539. AfteraSOUND-command,thesoundsometimescontinuesinspiteofthe
  3540. elapsedtime.IfthecommandisfollowedbyanotherSOUND-oraWAVE-
  3541. command,thetimeishandledcorrectly.ThiscertainlysoundslikeaGFA-
  3542. bug.
  3543.  
  3544. Theeasiestwaytostopallsoundis:
  3545.      WAVE0,0       !turnallsoundoff
  3546.  
  3547. Soundofacertainfrequencycanbeproducedwith:
  3548.      SOUNDch,vol,#ROUND(125000/freq%),pause
  3549.  
  3550. AlthoughourSTisnotfamousforitsbrilliantsound,youcanproduce
  3551. nicesound-effectswiththesimplecommandsSOUNDandWAVE.Checkoutthe
  3552. ProceduresSiren.sound,Tideli.sound,Bounce1.soundandBounce2.soundto
  3553. hearwhatImean.
  3554.  
  3555.  
  3556. üDosound(XBIOS32)Ç
  3557.  
  3558. XBIOS32(Dosound)canbeusedtoplaymusicinaspecialformat.I
  3559. proposetousetheextension'X32'forsong-filesinthisformat.The
  3560. operatingsystemtakescareofplayingthemusicduringinterrupts(every
  3561. 1/50thsecond).TakealookattheProceduresPlay.songandStop.songto
  3562. seehowyoucoulduseXBIOS32inyourprograms.Youcanevenplayasong
  3563. continuouslywiththeProcedurePlay.cont.song.Temporarilystoppinga
  3564. songispossiblewiththeProcedureInterrupt.song.
  3565.  
  3566. IfyouuseXBIOS32toplaymusic,youareadvisedtoswitchthekey-click
  3567. off.Otherwisethemusicwillstopassoonastheuserpressesakey.
  3568.  
  3569. OnceIdiscoveredXBIOS32didnotworkduringtheinitialization(mainly
  3570. thefillingofarrays)ofalargeprogram.Ihadconvertedtheprogram
  3571. fromGFA-Basic2.0to3.0,butIdidnothavethepatiencetofindout
  3572. whatcausedthisproblem.
  3573.  
  3574. XBIOS32canalsobeusedforsound-effects.Ihavedevelopedthe
  3575. ProcedureInitio.soundforbuildingsound-stringsfromafewDATA-lines.
  3576. Iherebydeclarethisasthestandardmethodforcreatingsound-strings.
  3577. After@do.sound(sound$)youcanhearthesound-effect.Inthefollowing
  3578. examplethesound-stringbounce3$iscreated:
  3579.      PROCEDURE initio.sound
  3580.        ' *** commands in DATA-lines :
  3581.        ' ***         REG = 14 parameters for registers 0-13
  3582.        ' ***         END = end of sound-string
  3583.        ' ***         PAUSE = pause (followed by time in 1/50 seconds)
  3584.        ' ***         VAR = decrease/increase tone : channel,start,+/-step,
  3585.      '***end-value
  3586. Ç       '
  3587.        bounce3.sound:
  3588.        DATA REG,0,0,0,0,0,0,27,248,16,16,16,35,95,0
  3589.        DATA VAR,3,255,-1,116
  3590.        DATA PAUSE,255,END
  3591.        RESTORE bounce3.sound
  3592.        @sound.string(bounce3$)
  3593.      RETURN
  3594.      ' 
  3595.      PROCEDURE sound.string(VAR s$)
  3596.        LOCAL n,snd$,snd,channel,begin,step,end
  3597.        s$=""
  3598.        DO
  3599.          READ snd$
  3600.          snd$=UPPER$(snd$)
  3601.          EXIT IF snd$="END"
  3602.          IF snd$="REG"
  3603.            FOR n=0 TO 13
  3604.              READ snd
  3605.              s$=s$+CHR$(n)+CHR$(snd)
  3606.            NEXT n
  3607.          ENDIF
  3608.          IF snd$="PAUSE"
  3609.            READ snd
  3610.            s$=s$+CHR$(130)+CHR$(snd)
  3611.          ENDIF
  3612.          IF snd$="VAR"
  3613.            READ channel,begin,step,end
  3614.            s$=s$+CHR$(128)+CHR$(begin)+CHR$(129)+CHR$(channel)+CHR$(step)
  3615.            s$=s$+CHR$(end)
  3616.          ENDIF
  3617.        LOOP
  3618.        s$=s$+CHR$(255)+CHR$(0)               ! terminator
  3619.      RETURN
  3620.      ' 
  3621.      PROCEDURE do.sound(sound$)
  3622.        VOID XBIOS(32,L:VARPTR(sound$))
  3623.      RETURN
  3624.  
  3625.  
  3626. üSamplesÇ
  3627.  
  3628. FromGFA-Basicyoucansurprisetheuserwithasampledsound.Examinethe
  3629. ProceduresSample,Load.sampleandPlay.sampletoseehow.You'llhaveto
  3630. findsuitablesamplesfirst.Lookoutforsound-effectsandspeech-
  3631. samples.Personally,IjustlovethefamousPerfect-sample.
  3632. ü
  3633.  
  3634. üSpeechÇ
  3635.  
  3636. YourSTcantalktoyouwithalittlehelp(STSPEECH.TOS).MycurrentGFA-
  3637. version(3.07)refusestocooperatewiththeProceduresInitio.speechand
  3638. Talk,butIhaveincludedtheseanyway.Perhapsyoucandiscoverthebug.
  3639. InearlierversionsbothProceduresdidwork.Aresetisnecessarybecause
  3640. EXEC3isused.
  3641.  
  3642.  
  3643. üSoundmachineÇ
  3644.  
  3645. Youcanplaysongs,createdwithSoundmachine(TommySoftware),fromGFA-
  3646. Basic.You'llneedtheProceduresInitio.soundmachineandSoundmachine,
  3647. andasong-file.You'llprobablywonderifit'sreallyyourSTthat's
  3648. playingthesong.SoundmachineIIisout,andlooksevenbetter.Inthis
  3649. newversionyoucanchoosebetweenplayingsongswithsamples,orwithout
  3650. samples(orsamplesforoneofthethreechannels).You'llneedthe
  3651. ProcedureSm.initioorMsm.initioandseveralothers.Trytofindthe
  3652. PublicDomaindemo-programsSAMSOUND.GFA,CHIPSND.GFAandSND_PLAY.GFA.
  3653. Endofcommercial,continuewithtext.
  3654.  
  3655.  
  3656. üë17.PROGRAMDECISIONS
  3657. Ç
  3658.  
  3659. üIF...ENDIFÇ
  3660.  
  3661. Ifthevalueofacertainvariablemustfallintherangemin%-max%,you
  3662. couldprogramthatasfollows:
  3663.      IFn%>max%
  3664.      n%=max%
  3665.      ENDIF
  3666.      IFn%<min%
  3667.      n%=min%
  3668.      ENDIF
  3669. InthiscaseyoucouldalsouseMAXandMIN:
  3670.      n%=MAX(MIN(n%,max%),min%)
  3671.  
  3672. Youprobablytestfortwoconditionsbyusing:
  3673.      IFcond1!ANDcond2!
  3674.      (...)                  !bothtrue
  3675.      ENDIF
  3676. Butseparatetestingismuchfaster:
  3677.      IFcond1!
  3678.      IFcond2!
  3679.      (...)                !bothtrue
  3680.      ENDIF
  3681.      ENDIF
  3682.  
  3683.  
  3684. üSELECTÇ
  3685.  
  3686. Multiple'ELSEIF'-constructionscanbereplacedbya'SELECT'-
  3687. construction.AteachCASEyoucanuseintegers,stringsorinteger-
  3688. variables(ênotÇstring-variables).Onlythefirstfourbytesofastring
  3689. canbeused.TheeditorwillnotacceptsomethinglikeCASE"test2",
  3690. onlyCASE"test".
  3691.  
  3692.  
  3693.  
  3694. üë18.PROGRAMLOOPS
  3695. Ç
  3696.  
  3697. üCalculationsÇ
  3698.  
  3699. Trytoremoveallunnecessarycalculationsfromloops,e.g.:
  3700.      FORi=1TO1000
  3701.      x(i)=2*q*i
  3702.      NEXTi
  3703. It'sabetterideatocalculate2*qoutsidetheloop:
  3704.      q2=q*2
  3705.      FORi=1TO1000
  3706.      x(i)=q2*i
  3707.      NEXTi
  3708.  
  3709. Alwaystrytoconvertfloatingpointvariablestointegersbeforeentering
  3710. aloop.Thenyouwillbeabletousethefastinteger-operators.An
  3711. obviousexamplewouldbeacalculationwithdollars(24.37)thatcouldbe
  3712. replacedbyacalculationwithcents(2437).Usethismethodifyouknow
  3713. thelowestpossiblevalueofthefloatingpointvariable(0.01inthis
  3714. case)andthendividebythisvalue.Butwatchoutforroundingerrorsand
  3715. integer-overflow.
  3716.  
  3717. Powersof2canbecalculatedfastbysettingabit:
  3718.      x%=BSET(0,6)   !fasterthanx%=2^6
  3719. Andfortheultimatespeed-freaks,multiplyingwithapowerof2is
  3720. slightlyfasterwithSHL:
  3721.      y%=SHL(x%,3)   !fasterthany%=MUL(x%,8)
  3722. Ofcoursethereisnooverflow-controlifyouuseSHL(orMUL).
  3723.  
  3724. Sometimes,calculationsinaloopcanbereplacedbyalook-uptable:
  3725.      FORi=1TO1000
  3726.      y%(i)=x|(i)^2
  3727.      NEXTi
  3728. First,createatableofsquares:
  3729.      DIMsquare%(255)
  3730.      FORi=0TO255
  3731.      square%(i)=i*i
  3732.      NEXTi
  3733. Thenusethistableintheloop:
  3734.      FORi=1TO1000
  3735.      y%(i)=square%(x|(i))
  3736.      NEXTi
  3737.  
  3738.  
  3739. üFOR...NEXTÇ
  3740.  
  3741. IuselocalvariablesinProceduresifpossible.Butifyouintendto
  3742. compiletheprogramlater,youshoulddeclarethecounterinaFOR...
  3743. NEXTloopasaêglobalÇvariable.Inthecompiledprogram,theloopwillbe
  3744. executedfaster!
  3745.  
  3746. ÇIfyouusefloatingpointcount-variablesinaFOR...NEXTloop(orany
  3747. otherloop),youcouldencounterunexpectedproblems:
  3748.      FORi#=0.1TO0.9STEP0.1
  3749.      PRINTi#
  3750.      NEXTi#
  3751. Youwouldexpect0.9astheresultofthelastaddition(0.8+0.1),but
  3752. 0.9isneverprinted!ThisisnotabuginGFA-Basic,butcausedbythe
  3753. internal(binary)representationoffloatingpointnumbers.Thelast
  3754. additionresultsinanumberslightlylargerthan0.9andthereforethe
  3755. loopisleftafterprinting0.8.Ifyouinserttheline
  3756.      i#=ROUND(i#,14)
  3757. intheloop,youcansolvethisproblem.Butthebestsolutionistoavoid
  3758. floatingpointcount-variablesinloops.Integercount-variablesaremuch
  3759. faster.Youcouldeasilychangetheloopto:
  3760.      FORi=1TO9
  3761.      PRINTUSING"#.#";i/10
  3762.      NEXTi
  3763. Onemoretime:'i'isaword-variable,becauseIuseword-variablesas
  3764. thedefaultfornumber-variableswithoutpostfix.
  3765.  
  3766. IfyouuseafloatingpointvariableinaREPEATUNTILloop,youcanavoid
  3767. theroundingerrorbyusingthespecialoperator'==':
  3768.      i#=0
  3769.      REPEAT
  3770.      i#=i#+0.1
  3771.      PRINTi#
  3772.      UNTILi#==0.9
  3773. Butyoucan'tusethe'=='-operatorinaFOR...NEXTloop.
  3774.  
  3775. Inthefollowingtwoexamplesabyte-variableisusedasthecounter:
  3776.      FORi|=5DOWNTO-1
  3777.      PRINTi|
  3778.      NEXTi|
  3779.      '     
  3780.      FORi|=250TO256
  3781.      PRINTi|
  3782.      NEXTi|
  3783. Ofcourse,abyte-variablecannothaveavalueof-1or256.GFAdoesênotÇ
  3784. abortwithanerror-message,butskipstheloops.Notatruebugperhaps,
  3785. butclose.
  3786.  
  3787.  
  3788. üLoopsÇ
  3789.  
  3790. AlthoughyoucanusemanydifferentloopsinGFA-Basic3.0,thereare
  3791. basicallyonlytwovarieties.Youcanfirsttestacondition,andthen
  3792. eithercontinueorleavetheloop.Oryoucanfirstentertheloop,and
  3793. thentestaconditiontodecideifyouaregoingtocontinueorleave.
  3794.  
  3795. InaninterpretedprogramthefirstchoiceisthefastFOR...NEXTloop,
  3796. thenthe(slower)REPEAT...UNTILloopandfinallythe(slowest)WHILE
  3797. ...WENDloop.Inacompiledprogramallloopsareexecutedequallyfast!
  3798. IfyouuseaDO...LOOP,anEXITIFconditionwillalwaystakesomeextra
  3799. time.
  3800. ÇTrytoavoidaênegativeÇtestinaloop,asthiswilltakemoretime.E.g.
  3801. replace:
  3802.      WHILENOTcondition!
  3803.      (...)
  3804.      WEND
  3805. bythemuchfaster:
  3806.      DOUNTILcondition!
  3807.      (...)
  3808.      LOOP
  3809. Orsimilarlyreplace:
  3810.      REPEAT
  3811.      (...)
  3812.      UNTILNOTcondition!
  3813. bythefaster:
  3814.      DO
  3815.      (...)
  3816.      LOOPWHILEcondition!
  3817.  
  3818. Finally,youcouldcombinethetestofoneconditionatthestartofthe
  3819. loopwiththetestofanotherconditionattheendoftheloop:
  3820.      DOUNTILcondition_1!
  3821.      (...)
  3822.      LOOPWHILEcondition_2!
  3823.  
  3824.  
  3825. üë19.PROGRAMCONTROL
  3826. Ç
  3827.  
  3828. üGOSUBÇ
  3829.  
  3830. AProcedurecanbecalledinoneofthefollowingways:
  3831.      GOSUBproc
  3832.      @proc
  3833.      proc
  3834. Ipreferthesecondmethod,becausethisisspottedeasilyinalisting.
  3835. Also,thesamemethodcanbeusedtocallafunction.
  3836.  
  3837.  
  3838. üONBREAKGOSUBÇ
  3839.  
  3840. Youcan'tstopaprogramifarecursivelycalledfunctionisexecuted(?).
  3841.  
  3842. UseONBREAKCONTtopreventcallingtheBreak-Proceduretwice.Nobodycan
  3843. releasethe<Control><Shift><Alternate>keysfastenough:
  3844.      ONBREAKGOSUBbreak
  3845.      (...)
  3846.      PROCEDUREbreak
  3847.      ONBREAKCONT
  3848.      (...)
  3849.      ONBREAKGOSUBbreak
  3850.      RETURN
  3851. InthiscasetheBreak-Procedureisactivatedagainbeforeleavingthe
  3852. Procedure.StudytheStandardProcedureBreak(inoneoftheSTANxxxx.LST-
  3853. files)foranexampleofthismethod.
  3854.  
  3855.  
  3856. üERRORÇ
  3857.  
  3858. YoucansimulateERRORswithvaluesfrom-127to127.ForGFA-errorsuse
  3859. valuesfrom0to93,forbomb-errors102(2bombs)to109(9bombs)and
  3860. forTOS-errors-1to-67.
  3861.  
  3862.  
  3863. üEVERYandAFTERÇ
  3864.  
  3865. It'snotpossibletouseEVERYandAFTERatthesametime.Bothcommands
  3866. don'tworkduringalongPAUSEorDELAY(oranyothercommandthattakesa
  3867. lotoftime).YoucanonlycallProcedureswithoutparameters.Don'tmake
  3868. theProceduretoolong,oritmaybecalledwhilebeingprocessed!
  3869.  
  3870. Inacompiledprogramyouhavetoincorporate'$I+U+',orEVERYandAFTER
  3871. can'tbeused.
  3872.  
  3873.  
  3874. üGOTOÇ
  3875.  
  3876. Youcan'tuseGOTOinaProcedure,aFunctionoraFOR...NEXTloop.
  3877.  
  3878.  
  3879. üDELAYÇ
  3880.  
  3881. TheDELAY-commanddoesnotoperatecorrectlyinversion3.07ofGFA-Basic.
  3882. DuringDELAYaBreakisimpossible.Anastierbugistheappearanceofthe
  3883. mouse-cursorduringDELAY,evenafterHIDEM.YouareadvisedtousePAUSE
  3884. instead.
  3885.  
  3886.  
  3887. üCHAINÇ
  3888.  
  3889. InGFA-BasicallvariablesandarraysarelostafterCHAINingthenext
  3890. program.However,youcouldusethe160-bytebufferofthescrap-library
  3891. topassashortmessagetothenextprogram:
  3892.      buffer$=SPACE$(160)           !160bytesmaximum??
  3893.      message$="thismessagewassentbythepreviousprogram"
  3894.      message$=message$+CHR$(0)
  3895.      LSETbuffer$=message$
  3896.      r%=SCRP_WRITE(buffer$)        !r%=0iferror
  3897.      CHAINfile$
  3898. Readthemessagewith:
  3899.      buffer$=SPACE$(160)
  3900.      r%=SCRP_READ(buffer$)
  3901.      message$=CHAR{V:buffer$}
  3902. Theuseofthisbufferiscompletelyillegal,butwhocaresifyoudon't
  3903. useascrap-library?UnfortunatelytheGFA-editorseemstothinksotoo,
  3904. soyoushouldexperimentalittlebeforetrustingthismethod.
  3905.  
  3906.  
  3907. üEXECÇ
  3908.  
  3909. Ifyouaregoingtorunanotherprogrammorethanonce,you'llhavetouse
  3910. EXEC3:
  3911.      base%=EXEC(3,file$,"","")          !load,butdon'tstartyet
  3912.      base$=STR$(base%)
  3913.      cmdl$=CHR$(LEN(base$)+1)+base$     !createcommandline
  3914.      (...)
  3915.      r%=EXEC(4,"",cmdl$,"")             !nowrunit
  3916. Thevariabler%containsavaluereturnedbytheprogram(or-39ifnot
  3917. enoughmemorywasavailable).Repeatthelastlineifyouwanttorunthe
  3918. loadedprogramagain.OfcourseyoushoulduseEXEC0ifyou'regoingto
  3919. runtheprogramonetimeonly.Readtheparagraph'RESERVE'ifyouare
  3920. goingtouseEXEC3.
  3921.  
  3922. Ifyoucalla'*.PRG'-programwithEXEC0,youpassthenull-string("")
  3923. asthecommand-line.Youneedthecommand-lineonlyifyoucalla'*.TTP'-
  3924. program.Thecommand-lineisconvertedtouppercaseandcan'texceed125
  3925. bytes.Thefirstbyteofthecommand-line(usually)determinesthelength
  3926. oftheline,sothecommand-linecan'tcontainmorethan124characters.
  3927. YoucanusethisinaTTP-program(compiledGFA-Basicprogram,extension
  3928. changedtoTTP),butit'seasiertoreadthecommand-linewith:
  3929.      cmdl$=CHAR{BASEPAGE+&H81}
  3930.  
  3931.  
  3932. üë20.GRAPHICS
  3933. Ç
  3934.  
  3935. üSETCOLORandVSETCOLORÇ
  3936.  
  3937. WithcommandslikeCOLOR,DEFTEXT,DEFFILL,etc.,youuseaVDIcolour-
  3938. index.UnfortunatelySETCOLORusesadifferenttable:
  3939.      VDIcolour-index    :0123456789101112131415
  3940.      SETCOLOR(Lowrez)  :0151246357891012141113
  3941.      SETCOLOR(Medrez)  :0312
  3942. Fromthistableitfollowsyouwouldhavetouse'SETCOLOR2,r,g,b'to
  3943. changecolour-indexê3Ç.Bytheway,allLine-AcommandsusetheSETCOLOR-
  3944. tableaswell!Thisisnota"bug",butaconsequenceoftwodifferent
  3945. colour-tablesthatareusedbyGEMDOSandGEM.Youareadvisedtouse:
  3946.      VSETCOLORindex,r,g,b
  3947. Thisindexisexactlythesameasthecolour-index,soyouwoulduse
  3948. 'VSETCOLOR2,r,g,b'inordertochangecolour-index2.Ifyoulike,you
  3949. couldusethehexadecimal3-bytemix-value:
  3950.      VSETCOLORindex,&Hrgb
  3951. Butyouwon'tlikeitatall,becausethisdoesn'tworkproperly.GFA-
  3952. Basicswapsther-andg-byte,soyouwouldhavetouse:
  3953.      VSETCOLORindex,&Hbgr
  3954. Betteravoidthismethod,oryou'llexperiencecolour-changesifGFA
  3955. correctsthisbuginafutureversion.
  3956.  
  3957. InHighresolutionyoucaninvertthescreen-colourswith:
  3958.      VSETCOLOR0,0       !reverseHigh-screen(blackbackground)
  3959.      VSETCOLOR1,0       !normalHigh-screen(blackletters)
  3960. Aninvertedscreenisperhapsslightlylesssuitablefortext,but
  3961. graphicslooksuperb.
  3962.  
  3963. Colour-index0determinesthecolourofthebackgroundinLowandMedium
  3964. resolution.Thisindexalsodeterminesthecolouroftheborderonyour
  3965. screen.Youcanchangethiscolour,althoughyoucan'tdraworPRINTon
  3966. thescreen-borderofyourcolourmonitor.ThecolourofallPRINTedtext
  3967. isdeterminedbycolour-index1,unlessyouusethe'Escb'command(read
  3968. theparagraph'PRINT'againifyourlong-termmemoryistooshort):
  3969.      VSETCOLOR0,r,g,b   !changecolourofbackground
  3970.      VSETCOLOR1,r,g,b   !changecolourofêallÇPRINTedtext
  3971.  
  3972.  
  3973. üPaletteÇ
  3974.  
  3975. Beforechangingcolours,youshouldalwayssavethecurrentpalette.And
  3976. dorestoretheoldpalettebeforetheuserexitstheprogram.Ihate
  3977. programsthatreturntoapinkoryellowdesktop.Youcanstorethe
  3978. paletteeitherinanintegerarrayorinastring,usingXBIOS7
  3979. (Setcolor):
  3980.  
  3981. Ç     PROCEDURE save.palette
  3982.        LOCAL i
  3983.        ERASE old.palette%()
  3984.        DIM old.palette%(15)
  3985.        FOR i=0 TO 15
  3986.          old.palette%(i)=XBIOS(7,i,-1)
  3987.        NEXT i
  3988.      RETURN
  3989.      '
  3990.      PROCEDURE make.palette.string(VAR pal$)
  3991.        LOCAL n
  3992.        pal$=""
  3993.        FOR n=0 TO 15
  3994.         pal$=pal$+MKI$(XBIOS(7,n,-1))
  3995.       NEXT n
  3996.      RETURN
  3997. Thestring-methodiscompatiblewithDegas.Restoretheoldpalettewith
  3998. thecorrespondingProcedures:
  3999.      PROCEDURE restore.palette
  4000.        LOCAL i
  4001.        FOR i=0 TO 15
  4002.          VOID XBIOS(7,i,old.palette%(i))
  4003.        NEXT i
  4004.      RETURN
  4005.      '
  4006.      PROCEDURE change.palette(pal.string$)
  4007.        VOID XBIOS(6,L:VARPTR(pal.string$))
  4008.      RETURN
  4009. YoucouldalsousetheStandardProcedureStandard.low.colorsor
  4010. Standard.med.colorstorestorethedefaultpalette.Youcanfindthese
  4011. ProceduresintheSTANxxxx.LST-files.
  4012.  
  4013. Youcanexaminethergb-valueofacertainVDIcolour-indexwith:
  4014.      PROCEDURE rgb.value(index,VAR rgb$)
  4015.        LOCAL col%
  4016.        col%=XBIOS(7,color.index(index),-1)
  4017.        rgb$=RIGHT$(HEX$(col%),3)
  4018.      RETURN
  4019. TheStandardArraycolor.index()isusedtoconverttheVDIcolour-index.
  4020.  
  4021. AcompletelynewpaletteforMediumresolutioncanbeinstalledwith:
  4022.      PROCEDURE new.med.colors
  4023.        LOCAL n,r,g,b,col$
  4024.        RESTORE med.new.col.data
  4025.        FOR n=0 TO 3
  4026.          READ col$
  4027.          r=VAL(LEFT$(col$))
  4028.          g=VAL(MID$(col$,2,1))
  4029.          b=VAL(RIGHT$(col$))
  4030.      VSETCOLORn,r,g,b
  4031.        NEXT n
  4032.      med.new.col.data
  4033.      DATA000,000,000,000
  4034.      RETURN
  4035. ÇYoucanshowthecurrentpaletteonthescreenwiththeProcedure
  4036. Palette.box:
  4037.      PROCEDURE palette.box(x,y,h,w)
  4038.        ' *** left upper corner of rectangle at x,y
  4039.        ' *** rectangle-height h; width of one colour-box w
  4040.        LOCAL arect.fill,fill.adr%,i,x1,x2
  4041.        x2=x+16*w+2
  4042.        COLOR black
  4043.        BOX x,y,x2,y+h
  4044.        arect.fill=-1
  4045.        f%=V:arect.fill
  4046.        IF low.res!
  4047.          FOR i=0 TO 15
  4048.            x1=ADD(SUCC(x),MUL(i,w))
  4049.            ARECT x1,SUCC(y),ADD(x1,w),PRED(ADD(y,h)),color.index(i),0,f%,0
  4050.          NEXT i
  4051.        ELSE IF med.res!
  4052.          FOR i=0 TO 3
  4053.            x1=ADD(SUCC(x),MUL(i,w))
  4054.            ARECT x1,SUCC(y),ADD(x1,w),PRED(ADD(y,h)),color.index(i),0,f%,0
  4055.          NEXT i
  4056.        ENDIF
  4057.      RETURN
  4058.  
  4059. Youcandarkenthescreenbydimmingallcolourssimultaneouslywiththe
  4060. ProcedureDim.colors:
  4061.      PROCEDURE dim.colors(reg1,reg2,val)
  4062.        ' *** dim colours from VDI colour-index reg1 to reg2 with val
  4063.        ' *** for val=1 colour 254 (rgb) will become 143
  4064.        LOCAL i,r,g,b
  4065.        FOR i=reg1 TO reg2
  4066.          @rgb.value(i,rgb$)
  4067.          r=MAX(PRED(VAL(LEFT$(rgb$))),0)
  4068.          g=MAX(PRED(VAL(MID$(rgb$,2,1))),0)
  4069.          b=MAX(PRED(VAL(RIGHT$(rgb$))),0)
  4070.          VSETCOLOR i,r,g,b
  4071.        NEXT i
  4072.      RETURN
  4073.  
  4074. NothingisimpossibleinGFA-Basic,evencolour-cyclingiseasywith
  4075. EVERY intheProcedureColor.cycle:
  4076.      PROCEDURE color.cycle(reg1,reg2,time)
  4077.        ' *** cycles colours from VDI colour-index reg1 to reg2
  4078.        ' *** global :  COLOR.CYCLE!  COL.REG1  COL.REG2
  4079.        IF NOT color.cycle!
  4080.          col.reg1=reg1
  4081.          col.reg2=reg2
  4082.          color.cycle!=TRUE
  4083.          EVERY time GOSUB cycle.once
  4084.        ELSE
  4085.          color.cycle!=FALSE
  4086.          EVERY STOP
  4087.        ENDIF
  4088.      RETURN
  4089. Ç     ' 
  4090.      PROCEDURE cycle.once
  4091.        LOCAL col1%,col2%
  4092.        col1%=XBIOS(7,color.index(col.reg2),-1)
  4093.        FOR reg=col.reg1 TO PRED(col.reg2)
  4094.          col2%=XBIOS(7,color.index(reg),-1)
  4095.          ~XBIOS(7,color.index(reg),col1%)
  4096.          SWAP col1%,col2%
  4097.        NEXT reg
  4098.        ~XBIOS(7,color.index(col.reg2),col1%)
  4099.      RETURN
  4100. CalltheProcedureColor.cycleagaintostopthecolour-cycling.
  4101.  
  4102.  
  4103. üDEFMARKÇ
  4104.  
  4105. Thepointasmark-symbol(No.1)cannotbeenlarged.Othermark-symbols
  4106. canbeenlarged,butalllinesinthesymbolretainawidthofonepixel.
  4107. Thesizeofasymbolmustbeamultipleof11plus6:0,17,28,39,50.
  4108. Foravalueinbetween,thepriorallowedsizeischosen.Perhapsthereis
  4109. somemagichiddenintheallowedsizes,oramImissingsomething?
  4110.  
  4111.  
  4112. üDEFFILLÇ
  4113.  
  4114. Ifyouhaven'tdefinedyourownFill-pattern,theAtari-symbolwillbe
  4115. usedafterDEFFILL1,4,x.ThedesktopFill-patternisDEFFILL1,2,4.
  4116.  
  4117. TheFill-patternstringcanconsistof16,32or64words(MKI$-format).
  4118. Word1to16isneededforbitplane0(Highresolution),word17to32for
  4119. bitplane1(Mediumresolution)andword33to64forthebitplanes2and3
  4120. (Lowresolution).Inallresolutions,thepatternoccupiesarectangleof
  4121. 16x16pixelsonthescreen.Thesame16x16rectangleisalsousedforthe
  4122. mouse-cursorandsprites.YoucanalwaysuseaFill-patterninaêlowerÇ
  4123. resolution,e.g.aHigh-patterninMediumorLowresolution,butnotthe
  4124. otherwayaround.ExaminethethreeProceduresInitio.high.fill1,
  4125. Initio.med.fill1andInitio.low.fill1toseehoweasyyoucandesignyour
  4126. ownFill-patterns.There'sgoldinthemtharFills.Youcouldsurprisethe
  4127. userwithabomb-pattern:
  4128.      PROCEDURE initio.bomb.fill
  4129.        ' *** global :  BOMB.FILL$
  4130.        RESTORE bomb.fill
  4131.        @make.high.fill(bomb.fill$)
  4132.       bomb.fill:
  4133.      DATA 0000011000000000
  4134.      DATA0010100100000000
  4135.      DATA0000000010000000
  4136.      DATA0100100001000000
  4137.      DATA 0001000111110000
  4138.      DATA 0000000111110000
  4139.      DATA 0000011111111100
  4140.      DATA 0000111111111110
  4141.      DATA 0000110111111110
  4142.      DATA 0001111111111111
  4143. Ç     DATA 0001111111101111
  4144.      DATA 0000111111101110
  4145.      DATA 0000111111011110
  4146.      DATA 0000011111111100
  4147.      DATA 0000001111111000
  4148.      DATA 0000000011100000
  4149.      RETURN
  4150.      ' 
  4151.      PROCEDURE make.high.fill(VAR fill$)
  4152.        LOCAL i,pat$,pat%
  4153.        CLR fill$
  4154.        FOR i=1 TO 16
  4155.          READ pat$
  4156.          pat%=VAL("&X"+pat$)
  4157.      fill$=fill$+MKI$(pat%)
  4158.        NEXT i
  4159.      RETURN
  4160.  
  4161. Becareful,ascreenfilledwiththispatternmightprovokeaheart-
  4162. attack.Ifitdoesn't,youcouldtrythefollowingdirtytrick(High
  4163. resolutiononly)withtheProceduresBusyandAchtung:
  4164.      @busy          !lookslikethecomputerisverybusy
  4165.      ~INP(2)        !butnothinghappens,untiltheuserpressesakey...
  4166.      @achtung
  4167.      PAUSE500
  4168.      CLS
  4169.      PRINT"Thankyouforyourpatience,I'mnotbusyanymore..."
  4170.      PAUSE150
  4171.  
  4172. ManyFill-patternsareavailableasfiles.Youcanusethesewith
  4173. somethinglikeProcedureInitio.fill1:
  4174.      PROCEDURE initio.fill1(VAR pattern$)
  4175.        LOCAL bytes
  4176.        bytes=32         ! 32 bytes for High resolution
  4177.        ' *** load Fill-pattern (32 bytes for High resolution) here
  4178.        INLINE fill1%,32
  4179.        pattern$=STRING$(bytes,0)
  4180.        BMOVE fill1%,V:pattern$,bytes
  4181.        DEFFILL ,pattern$
  4182.      RETURN
  4183.  
  4184. FILLingascreenwithapatterntakessometime,especiallyinHigh
  4185. resolution.Usethefollowingmethodforalmostimmediatefillingofthe
  4186. entireHighresolutionscreen:
  4187.      PROCEDUREfull.fill(fill%)
  4188.      ACLIP1,0,0,639,399
  4189.      ARECT0,0,639,399,1,0,fill%,15
  4190.      ACLIP0,0,0,639,399
  4191.      RETURN
  4192. Fill%istheaddressofaFILL-pattern(32bytes).Thisveryfast
  4193. alternativeFill-methodworksinHighresolutiononly.
  4194.  
  4195.  
  4196. üDEFLINEÇ
  4197.  
  4198. After'DEFLINE,n'allhorizontallineshaveawidthofnpixels(nshould
  4199. beodd),exceptinMediumresolution.Butifnislargerthan1,all
  4200. verticallinesaren+2pixelswide!Ihavetroublecountingthepixels
  4201. inMediumresolution.Ithinkthewidthofhorizontallinesis:
  4202.      n:   13579
  4203.      width :   11335etc.
  4204. Isthisdocumentedanywhere?
  4205.  
  4206. YoudefineyourownLine-patternsbyusinganegative16-bitvalue(from
  4207. -&X1to-&X1111111111111111).Eachsetbitcorrespondswithapixelinthe
  4208. Line-pattern(Highresolution).Thehighestbit(15)correspondswiththe
  4209. leftmostpixelofthepattern.Don'tgetconfusediftheeditorchanges
  4210. thenegativebinarynumberyouenteredasapattern.Theeditorusesa
  4211. specialnotationfornegativebinarynumbers.
  4212.  
  4213. GFA-Basicrepresentsintegernumbersasbinarystringsof32bits.The
  4214. mostsignificantbit(31)determinesthesignoftheinteger.Ifthisbit
  4215. is0,theremaining31bitsrepresentan"ordinary"positivenumber.But
  4216. ifthemostsignificantbitis1,theremainderisanegativenumberin
  4217. 'two'scomplement'notation.Iwon'ttrytoexplainthat.Inanycase,the
  4218. nexttimeyoutype-&X111andafriendiswatchingyou,don'tblinkyour
  4219. eyes,butcasuallyremark"ofcoursetheeditorconvertsthisintotwo's
  4220. complementnotation".That'salsothereasonGFA-Basiccanworkwith
  4221. integersfrom-(2^31)to+(2^31)-1.
  4222.  
  4223.  
  4224. üDEFTEXTÇ
  4225.  
  4226. Insomepublicationsyoucanreadabout'shadowedtext'(style=32),but
  4227. unfortunatelyourGEMdoesn'tknowthisstyle.Youcanevenfindthemask
  4228. forshadowedtextwithWORD{L~A+92},butit's0.
  4229.  
  4230. Ineversucceededinfindingthecurrenttext-stylewithVDISYS38
  4231. (vqt_attributes).EitherabuginGEMormymistake.Idon'twanttoknow,
  4232. becausetheeasywayis:
  4233.      txt.style=WORD{L~A+90}
  4234. ThiscouldbeimportantifyouintendtouseDEFTEXTinaProcedure,but
  4235. wouldliketorestoretheoriginalDEFTEXT-settingsbeforeleavingthe
  4236. Procedure.
  4237.  
  4238. WithDEFTEXTyoucansettheheightofTEXT-letters.Aletteroccupies
  4239. morespacethough,determinedbytheletter-box:
  4240.  
  4241.      êletter-heightÇ  êletter-boxÇ     êsystem-fontÇ
  4242.           4        6x6        icon
  4243.           6        8x8        Medium&Lowrez
  4244.           13        8x16       Highresolution
  4245.  
  4246. Theletter-heightisthedistancefromDescent-LinetoAscent-Line,but
  4247. theBottom-LineandTop-Linelieatleastonepixellower/higher.The
  4248. heightoftheletter-boxisthedistancefromBottom-LinetoTop-Line.
  4249. ÇMostlettersrestontheBase-Line,butletterswithadescender(g,j,p,
  4250. etc.)restontheDescent-Line.Ifyouarestillwithme,fromtopto
  4251. bottomwehavethefollowinglines:
  4252.      Top-Line
  4253.      Ascent-Line
  4254.      Base-Line
  4255.      Descent-Line
  4256.      Bottom-Line
  4257. Dropmealineifyoudon'tunderstandthis.
  4258.  
  4259.  
  4260. üGRAPHMODEÇ
  4261.  
  4262. IfyoudrawarectanglewithBOXinGRAPHMODE3(Xor-mode),thepixelin
  4263. theleftuppercornerisnotdrawn.Actuallythispixelisdrawntwice,
  4264. andinGRAPHMODE3thismeansthepixeldisappears.UsePLOTtodrawthis
  4265. pixel:
  4266.      GRAPHMODE3
  4267.      BOXx1,y1,x2,y2
  4268.      PLOTx1,y1          !andfillthegap
  4269.  
  4270. WithPBOXinGRAPHMODE3you'llalsogettroubleinthesamecorner.Avoid
  4271. thisbyusingthecommand'BOUNDARY0'first:
  4272.      GRAPHMODE3
  4273.      BOUNDARY0 
  4274.      PBOX50,50,100,100
  4275.  
  4276. GRAPHMODE3isespeciallyusefulifyoumakeatemporarydrawing.Drawthe
  4277. samepictureasecondtimetorestoretheoriginalscreen.ExamineProce-
  4278. dureslikeRubber.line,Draw.boxandDrag.boxforexamplesofthismethod.
  4279. TheProcedureRubber.lineisusedtodrawalinefrom(x,y)tothemouse-
  4280. cursor:
  4281.      PROCEDURE rubber.line(x,y,VAR x2,y2)
  4282.        LOCAL x1,y1,x2,y2,k
  4283.        GRAPHMODE 3
  4284.        DEFMOUSE 3
  4285.        SHOWM
  4286.        MOUSE x1,y1,k
  4287.        REPEAT                           !mainloop
  4288.          LINE x,y,x1,y1                 !drawline
  4289.          REPEAT
  4290.      MOUSE x2,y2,k
  4291.          UNTIL x2<>x1 OR y2<>y1 OR k>0  !mousemoved
  4292.          LINE x,y,x1,y1                 !undrawline
  4293.          x1=x2
  4294.          y1=y2
  4295.        UNTIL k>0         !mouse-click:ready(x2andy2returned)
  4296.        GRAPHMODE 1
  4297.        LINE x,y,x2,y2    !thisisit
  4298.        HIDEM
  4299.        DEFMOUSE 0
  4300.        PAUSE 10
  4301.      RETURN
  4302.  
  4303. ÇYoucouldalsousethe'GRAPHMODE3'-methodforanimation,buttheXBIOS5
  4304. (Setscreen)methodismoresuitable.
  4305.  
  4306. Don'ttrytodrawinGRAPHMODE3withalinewidthgreaterthan1pixel.
  4307. GEMwillsurpriseyouwithsomemodernartifyoucan'tresistthe
  4308. temptation.
  4309.  
  4310. Ifyouwanttoconfirmaparticularchoiceoftheuser,youcaninvertthe
  4311. relevantpartofthescreenwiththeProcedureInvert.block.Callthis
  4312. Procedureagainwiththesameparameterstorestoretheoriginalscreen:
  4313.      PROCEDURE invert.block(x1,y1,x2,y2,color)
  4314.        GRAPHMODE 3
  4315.        DEFFILL color,1
  4316.        BOUNDARY 0
  4317.        PBOX x1,y1,x2,y2
  4318.        BOUNDARY 1
  4319.       GRAPHMODE 1
  4320.      RETURN
  4321.  
  4322. Youcan'greyout'anunavailableoptiononthescreenwith:
  4323.      PROCEDURE block.dimmer(x1,y1,x2,y2,color)
  4324.        GRAPHMODE 3
  4325.        DEFFILL color,2,2
  4326.        BOUNDARY 0
  4327.        PBOX x1,y1,x2,y2
  4328.        BOUNDARY 1
  4329.        GRAPHMODE 1
  4330.      RETURN
  4331. CallthisProcedureagaintorestorethescreen.
  4332.  
  4333. Theentire(Highresolution)screencanbedimmedwith:
  4334.      PROCEDURE screen.dimmer
  4335.        ' *** global :   DIMMER.SCREEN$DIMMER.SWITCH!
  4336.        IF dimmer.switch!
  4337.        SPUT dimmer.screen$
  4338.          dimmer.switch!=FALSE
  4339.        ELSE
  4340.          SGET dimmer.screen$
  4341.          GRAPHMODE 4
  4342.          DEFFILL 1,2,4
  4343.          PBOX 0,0,639,399
  4344.      dimmer.switch!=TRUE
  4345.        ENDIF
  4346.      RETURN
  4347. ThescreenwillberestoredifyoucalltheProcedureagain.
  4348.  
  4349.  
  4350. üPLOTandDRAWÇ
  4351.  
  4352. Youcanuseboth'PLOTx,y'and'DRAWx,y'tosetapointonthescreen.
  4353. Thesizeofthepointcanbechanged:
  4354.      DEFLINE,size,2,2   !changesizeofpoints
  4355. ÇButtheshapesyou'llseedon'tlooklikepointsanymore,duetothesame
  4356. problemasdescribedintheparagraph'DEFLINE'.UsePCIRCLEforproper
  4357. fatpoints.
  4358.  
  4359.  
  4360. üPCIRCLEÇ
  4361.  
  4362. WithCLIPon,aPCIRCLEtouchingtheupperscreen-borderisnotfilled
  4363. properlyinHighresolution:
  4364.      CLIP0,0,640,400
  4365.      PCIRCLE0,0,50
  4366. Idon'tknowifweshouldblameGFAorGEMfornotfillingthetwotop-
  4367. linesinthecircle.
  4368.  
  4369.  
  4370. üCURVEÇ
  4371.  
  4372. WiththecommandCURVEyoucandrawaBezier-curve:
  4373.      CURVEx1,y1,x2,y2,x3,y3,x4,y4
  4374. TheBezier-curvestartsat(x1,y1)andendsat(x4,y4).Theothertwo
  4375. pointsactlikelittlemagnets.Youcanalsousethiscommandtodrawa
  4376. 'normal'curvebetweentwopointsbylettingthepoints(x3,y3)and
  4377. (x4,y4)coincide.TrythefollowingtoseewhatImean:
  4378.      GRAPHMODE3
  4379.     MOUSEx2,y2,k
  4380.      DO
  4381.      CURVE10,100,x2,y2,110,100,110,100    !drawcurve
  4382.      REPEAT
  4383.        MOUSEx,y,k
  4384.      UNTILx<>x2ORy<>y2
  4385.      CURVE10,100,x2,y2,110,100,110,100 !erasecurve
  4386.      x2=x
  4387.      y2=y
  4388.      LOOP
  4389. Thismethodcouldbeusedtodrawlargeletters.
  4390.  
  4391.  
  4392. üTEXTÇ
  4393.  
  4394. ThecoordinatesusedwithTEXTdeterminethestartoftheêBase-LineÇofthe
  4395. text.Thedescendersofletterslike'g','j',and'p'liebelowtheBase-
  4396. Line.Thisisespeciallyimportant,nottosayfrustrating,ifyouuse
  4397. TEXTwithanangleof90,180or270degrees.Thetextrotatesanticlock⑨
  4398. wisearoundtheTEXT-coordinates!
  4399.  
  4400. IfyouintendtocombinePRINTedtextwithTEXT,youprobablywilllike
  4401. theProcedureText.atastheanalogueof'PRINTAT':
  4402.      PROCEDURE text.at(c,l,t$)
  4403.       TEXT (c-1)*char.width,l*char.height+3*high.res!+2*(NOT high.res!),t$
  4404.      RETURN
  4405.  
  4406. ÇYoucanuseTEXTtoprint"digital"numbers(ASCII-code16-25):
  4407.      FUNCTION digital$(number$)
  4408.        LOCAL dig$,i
  4409.        CLR dig$
  4410.        FOR i=1 TO LEN(number$)
  4411.          dig$=dig$+CHR$(BCLR(ASC(MID$(number$,i,1)),5))
  4412.        NEXT i
  4413.        RETURN dig$
  4414.      ENDFUNC
  4415. UsethisFunctionasfollows:
  4416.      TEXT x,y,@digital$("1237")
  4417.  
  4418.  
  4419. üSPRITEÇ
  4420.  
  4421. YoucoulddesignandsavespritesäinvitroÇwithoneofthemanySprite-
  4422. editorsthatareavailable.OryoucanusesomethingliketheProcedure
  4423. Initio.sprite1tocreateaspriteäinvivoÇ.ComparethisProcedurealso
  4424. withtheProcedureInitio.mouse1:
  4425.      PROCEDURE initio.sprite1
  4426.        ' *** global :  SPRITE1$
  4427.        RESTORE pattern.sprite1
  4428.        @make.sprite(sprite1$)
  4429.        pattern.sprite1:
  4430.        ' *** x,y,mode(0=normal;1=XOR),mask-colour,sprite-colour
  4431.        DATA 0,0,0,0,1
  4432.        ' *** mask-pattern (1 = pixel on , 0 = pixel off)
  4433.        DATA 0000000000000000
  4434.        DATA 0000000000000000
  4435.        DATA 0000000000000000
  4436.        DATA 0000000000000000
  4437.        DATA 0000000000000000
  4438.        DATA 0000000000000000
  4439.        DATA 0000000000000000
  4440.        DATA 0000000000000000
  4441.      DATA 0000000000000000
  4442.        DATA 0000000000000000
  4443.        DATA 0000000000000000
  4444.        DATA 0000000000000000
  4445.        DATA 0000000000000000
  4446.        DATA 0000000000000000
  4447.        DATA 0000000000000000
  4448.        DATA 0000000000000000
  4449.        ' *** sprite-pattern
  4450.        DATA 0000000000000000
  4451.        DATA 0000000000000000
  4452.        DATA 0000000000000000
  4453.        DATA 0000000000000000
  4454.        DATA 0000000000000000
  4455.      DATA 0000000000000000
  4456.        DATA 0000000000000000
  4457.        DATA 0000000000000000
  4458.        DATA 0000000000000000
  4459.        DATA 0000000000000000
  4460. Ç       DATA 0000000000000000
  4461.        DATA 0000000000000000
  4462.        DATA 0000000000000000
  4463.        DATA 0000000000000000
  4464.        DATA 0000000000000000
  4465.        DATA 0000000000000000
  4466.      RETURN
  4467.      ' 
  4468.      PROCEDURE make.sprite(VAR s$)
  4469.        LOCAL x,y,mode,msk.color,spr.color,n,msk%,spr%,msk.pat$,spr.pat$
  4470.      LOCALmsk$,spr$,pat$
  4471.        CLR msk.pat$,spr.pat$,pat$
  4472.        READ x,y,mode,msk.color,spr.color
  4473.        FOR n=1 TO 16
  4474.          READ msk$
  4475.          msk%=VAL("&X"+msk$)
  4476.      msk.pat$=msk.pat$+MKI$(msk%)
  4477.       NEXT n
  4478.        FOR n=1 TO 16
  4479.          READ spr$
  4480.      spr%=VAL("&X"+spr$)
  4481.          spr.pat$=spr.pat$+MKI$(spr%)
  4482.        NEXT n
  4483.        FOR n=1 TO 16
  4484.          pat$=pat$+MID$(msk.pat$,n*2-1,2)+MID$(spr.pat$,n*2-1,2)
  4485.        NEXT n
  4486.        s$=MKI$(x)+MKI$(y)+MKI$(mode)+MKI$(color.index(msk.color))
  4487.        s$=s$+MKI$(color.index(spr.color))+pat$
  4488.      RETURN
  4489. Themaskshouldbeanexactcopyofthesprite-patternifyouneeda
  4490. transparantsprite.Leavethemaskempty(all'0')andthespritewill
  4491. disappearbehindobjectsonthescreen.Fillthemaskwith'1'andthe
  4492. 16x16spritewillalwaysremainvisible.Switchmask-andsprite-colourin
  4493. thefirstDATA-linetocreatea"reverse"sprite.OruseanyVDIcolour-
  4494. indexthatisavailableinthecurrentresolution.
  4495.  
  4496. Ifyouputaspriteonthescreen,thebackground(16x16pixels)is
  4497. temporarilysaved.Usingmorethanonespritesimultaneously,itis
  4498. essentialyouremovespritesinreverseorder.Thisisnecessarybecausea
  4499. spritecouldoverlapanothersprite.Removingthetopspritefirstensures
  4500. thattheoriginalbackgroundwillreappearafterremovingthefirst
  4501. sprite,e.g.:
  4502.  
  4503.      DO
  4504.      (...)
  4505.      SPRITEs2$        !removesprites...
  4506.      SPRITEs1$
  4507.      VSYNC             !preventsblinking,butslowsdown
  4508.      SPRITEs1$,x1,y1 !drawsprites...
  4509.      SPRITEs2$,x2,y2
  4510.      (...)
  4511.      LOOP
  4512.  
  4513.  
  4514. üVQT_EXTENTÇ
  4515.  
  4516. ThefunctionVQT_EXTENTcanbeusedifyouwouldliketodrawarectangle
  4517. aroundatext-string:
  4518.      ~VQT_EXTENT(txt$,x1,y1,x2,y2,x3,y3,x4,y4)
  4519. Thecoordinatesofthefourcornersdependontheangleofthetext(0,
  4520. 90,180or270degrees)andofcourseonthesizeofthetext.Thepoint
  4521. (x1,y1)isthelowerleftcorneroftheimaginaryrectanglearoundthe
  4522. textandtheotherpointsarearrangedanticlockwisearoundthetext-
  4523. string.BecausethetextrotatesaroundtheTEXT-coordinates(startofthe
  4524. Base-Line),itwilltakesometrialanderrortodeterminethecorrect
  4525. positionoftherectangleiftheangleisnot0degrees.Inthefollowing
  4526. tableyou'llfindthe"true"originoftherectangle,thewidthandthe
  4527. heightoftherectangle,andalsotheactualpositionofthelowerleft
  4528. cornerofthetext-block(x1,y1):
  4529.      êangleÇ     êposition(x1,y1)Ç    êoriginÇ    êwidthÇ     êheightÇ
  4530.      0         lowerleft       x1,y1    x2       y4
  4531.      900      lowerright      x4,y4    x1       y3
  4532.      1800         upperright      x3,y3    x4       y2
  4533.      2700      upperleft       x2,y2    x3       x4
  4534. Thecoordinatesoftheoriginare(0,0),sowithanangleof0degrees
  4535. bothx1andy1are0.Therectanglerestsonthex-axis,whiletheleft
  4536. sidecoincideswiththey-axis.Thisisa"mathematical"y-axis,nota
  4537. "screen"y-axis.Thismeansyougoupwardsforpositivey-values.Foran
  4538. angleof0degreesthecoordinateswillbe:
  4539.      (x4,y4)..(x3,y3)
  4540.      .TEXTBLOCK.
  4541.      (x1,y1)(x2,y2)
  4542.  
  4543. Ifyouunderstandthetable,youshouldbesurprisedbytheheight'x4'
  4544. insteadof'y1'atanangleof270degrees.IthinkIdiscoveredabugin
  4545. GEMhere.CorrectGEMbychangingthefollowingvariablesifanangleof
  4546. 270degreesisused:
  4547.      y1=x4
  4548.      SWAPx4,y4
  4549. Now,theheightis'y1'asyoususpected.Clever,aren'twe?Ihavenot
  4550. beenabletoconfirmmydiscovery.Noneofmyreference-booksmentionthe
  4551. bug.
  4552.  
  4553.  
  4554. üLine-AÇ
  4555.  
  4556. TheLine-AcommandsarefasterthanthecorrespondingVDI-commandsinGFA-
  4557. Basic.ThedifferenceshouldbeevengreaterafterloadingGDOS(?).In
  4558. thefollowingtableyoucanfindhowmanytimesfastertheLine-Acommand
  4559. is:
  4560.      PSET/PLOT=3
  4561.      PTST/POINT=2
  4562.      HLINE/LINE=2
  4563.      ARECT/PBOX=1.5
  4564. ThesyntaxofLine-Acommandsismorecomplicated,butthat'snoproblem
  4565. forusGFA-experts.Line-Acommandsusethe'SETCOLOR-index',soyou'll
  4566. probablyneedtheStandardArraycolor.index().
  4567.  
  4568. üHLINEÇ
  4569.  
  4570. AnadditionaladvantageofthecommandsHLINE,ARECTandAPOLYisthatyou
  4571. don'thavetochangetheDEFFILL-parametersinthemainprogram.Forsolid
  4572. horizontallines,use:
  4573.      pattern=-1
  4574.      adr%=V:pattern
  4575.      HLINEx1,y,x2,color,mode,adr%,0
  4576. Youcan'tuse&X1111111111111111(16bits)forthepattern,becausebit15
  4577. ofaword-variableisaflagforanegativenumber.Yes,that'swhythe
  4578. largestpositivewordis2^15-1(32767).Thesolutiontothislittle
  4579. problemistoassign-1totheword-variable.Youhavemyword,nowall16
  4580. bitsare1.UseBIN$ifyoudon'tbelieveme.
  4581.  
  4582. Forverycomplicatedpatternsyoucoulduseaword-array:
  4583.      DIMpattern(i)
  4584.      adr%=V:pattern(0)
  4585.      (...)               !putfill-patterninpattern(0)topattern(i)
  4586.      HLINEx1,y,x2,color,mode,adr%,i
  4587.  
  4588.  
  4589. üACHARÇüandATEXTÇ
  4590.  
  4591. It'sdifficulttocombinetheLine-AcommandsACHARandATEXTwithTEXT.
  4592. ThecoordinatesusedwithACHARandATEXTdeterminethepositionofthe
  4593. leftuppercornerofthe(first)letter-box.That'stheTop-Line,ênotÇthe
  4594. Base-Line.
  4595.  
  4596. Youcan'tusethetext-styleunderlined(8)withACHARandATEXT.Probably
  4597. aGFA-bug.
  4598.  
  4599.  
  4600. üGETandPUTÇ
  4601.  
  4602. Youcouldsavearectangularpartofthescreenasfollows:
  4603.      GETx1,y1,x2,y2,pic$
  4604.      BSAVEfile$,V:pic$,LEN(pic$)  !usetheextensionPUTinthefilename
  4605.  
  4606. Later,youcouldputthesavedpicturebackonthescreenwith:
  4607.      OPEN"I",#1,file$
  4608.      LETbytes%=LOF(#1)            !howmanybytesneeded?
  4609.      CLOSE#1
  4610.      picture$=SPACE$(bytes%)       !reservesomespace,
  4611.      BLOADfile$,V:picture$        !loadthepicture
  4612.      PUTx,y,picture$              !andlookatit
  4613.  
  4614. TheProceduresMessage,Warning,Message.onandMessage.offuseGETand
  4615. PUTtosaveandlaterrestorethepartofthescreenthatisusedfor
  4616. text.
  4617.  
  4618. ÇAGET-stringstartswiththreewordsforwidth,heightandnumberof
  4619. bitplanes.Thenumberofbitplanesisdeterminedbytheresolution:1for
  4620. High,2forMediumand4forLow.Afterthesethreewordsfollowsthe
  4621. actualpictureasalistofwords.Asthepicture-widthisnotnecessarily
  4622. amultipleof16,anybitsbeyondtherightborderwillbeignoredbythe
  4623. PUT-command.
  4624.  
  4625. HereistheconnectionbetweenGRAPHMODEandPUT-mode:
  4626.      êGRAPHMODEÇ      êPUT-modeÇ
  4627.          1             3(default)
  4628.          2             7
  4629.          3          6
  4630.          4          13
  4631. IhaveencounteredafewprogramsinGFA-Basic2.0wherePUTwasused
  4632. justoutsidethescreen.InGFA-Basic3.0theprogramdidn'twork.The
  4633. sameoccurredinaprogramwhereapicturewasBLOADedafewbytesbefore
  4634. thescreen-RAM.Idon'tunderstandwhyGFA-Basic3.0doesn'tacceptthis,
  4635. asthereissomeunusedspacethere(readtheparagraph'RAM'),butI've
  4636. learnedtocorrectthiswhenIconvertaprogramfromGFA-Basic2.0to
  4637. version3.0.
  4638.  
  4639.  
  4640. üDegas-PicturesÇ
  4641.  
  4642. ADegaspicture-filecontainsnotonlytheactualpicture(sameformatas
  4643. SGET-picture),butalsothecolour-palette.UsetheProcedureShow.degas
  4644. toloadandshowaDegas-picture:
  4645.      PROCEDURE show.degas(degas$)
  4646.        LOCAL degas.picture$,degas.picture%,degas.palette$
  4647.      LOCALdegas.palette%
  4648.          degas.picture$=SPACE$(32000)
  4649.          degas.picture%=VARPTR(degas.picture$)
  4650.          degas.palette$=SPACE$(32)
  4651.          degas.palette%=VARPTR(degas.palette$)
  4652.          OPEN "I",#90,degas$
  4653.          SEEK #90,2                          !skipresolution
  4654.          BGET #90,degas.palette%,32            ! load palette of picture
  4655.          SEEK #90,34
  4656.          BGET #90,degas.picture%,32000         ! load actual picture
  4657.          CLOSE #90
  4658.          ~XBIOS(6,L:degas.palette%)            ! change palette
  4659.          SPUT degas.picture$                   ! show the picture
  4660.      RETURN
  4661.  
  4662. TheoriginalDegas-fileshavealengthof32034bytes:
  4663.      1word         -resolution
  4664.      16words       -palette
  4665.      16000words    -picturedata
  4666. YoucanuseBTSTtochecktheresolution(bit0=Low,bit1=Medium,bit
  4667. 2=High),butyoucouldalsolookattheextensionofthefilename
  4668. (PI1/PI2/PI3forLow/Medium/High).InthesecondDegas-version(Degas
  4669. Elite),16wordsfor"colour-animation"canbeaddedafterthepicture
  4670. data.
  4671. ÇADegasElitepicturecan(andreallyshould!)besavedinacompressed
  4672. format.TheextensionsPC1/PC2/PC3areusedforLow/Medium/High
  4673. resolution.Also,thehighestbitoftheresolution-wordissetasaflag
  4674. foracompressedpicture.WiththeProcedureShow.comp.degasyoucanload
  4675. andshowacompressedDegas-picture.
  4676.  
  4677.  
  4678. üNeochrome-PicturesÇ
  4679.  
  4680. Sometimesthe"Neochrome"-formatisusedforpictures(32128bytes):
  4681.      1integer           -resolution(0/1/2forLow/Medium/High)
  4682.      16words            -palette
  4683.      12bytes            -filename(nnnnnnnn.eee)
  4684.      4bytes+1word    -colouranimationdata
  4685.      18integers         -reserved
  4686.      16000words         -picturedata
  4687.  
  4688.  
  4689. üVSYNCÇ
  4690.  
  4691. TheVSYNC-commandisusefulifyouwanttopreventirritatingblinking
  4692. duringanimation.AlwaysVSYNCbeforedrawinganewpictureinan
  4693. animationsequence(includingSPRITE-animation).Theprogramisslowed
  4694. downofcourse,becauseitwaitsforaverticalblankinterruptbefore
  4695. startingtodraw.Butitlooksmuchnicer.
  4696.  
  4697.  
  4698. üScrollÇ
  4699.  
  4700. WithBMOVEandRC_COPYyoucanaccomplishprettysmoothscrolling.GET/PUT
  4701. istooslow,andonlyworksonthelogicalscreen.BITBLTismore
  4702. flexible,butalsomorecomplicated.Andnotfaster(?).Studythe
  4703. ProceduresScroll.upandScroll.downtoseehowyoucouldscrollthe
  4704. entirescreenupordown:
  4705.  
  4706.      PROCEDURE scroll.up(scroll.lines,scroll.color)
  4707.        LOCAL n,bytes,move.bytes,source%
  4708.        IF high.res!
  4709.          LET bytes=80*scroll.lines
  4710.        ELSE
  4711.          LET bytes=160*scroll.lines
  4712.        ENDIF
  4713.        move.bytes=32000-bytes
  4714.        source%=physbase%+bytes
  4715.        VSYNC
  4716.        BMOVE source%,physbase%,move.bytes 
  4717.        DEFFILL scroll.color
  4718.        PBOX 0,scrn.y.max-scroll.lines+1,scrn.x.max,scrn.y.max 
  4719.        FOR n=1 TO DIV(scrn.y.max,scroll.lines)                
  4720.          VSYNC
  4721.          BMOVE source%,physbase%,move.bytes
  4722.        NEXT n
  4723.      RETURN
  4724. ÇCananybodyexplaintheinterferencelinesthatsometimesappearduring
  4725. thescrolling?
  4726.  
  4727. Severalfade-overeffectscanbefoundintheProceduresUp.scroll,
  4728. Slider.scroll,etc.MostProcedurescanonlybeusedinHighresolution.
  4729.  
  4730. Forscrollingofoneormoretext-linesyoucouldusetheProcedures
  4731. Scroll.text.upandScroll.text.down:
  4732.      PROCEDURE scroll.text.up(begin,end)
  4733.        LOCAL screen%,sx,sy,w,h,dx,dy
  4734.        IF begin>1 AND end>=begin
  4735.          screen%=XBIOS(3)          ! logical screen
  4736.          sx=0
  4737.          sy=(begin-1)*char.height
  4738.          w=scrn.x.max
  4739.          h=(end-begin+1)*char.height
  4740.          dx=0
  4741.          dy=sy-char.height
  4742.          RC_COPY screen%,sx,sy,w,h TO screen%,dx,dy
  4743.        ELSE
  4744.          PRINT bel$;
  4745.        ENDIF
  4746.      RETURN
  4747. ThismethodisalsousedintheProcedureDebug.
  4748.  
  4749.  
  4750. üACLIPÇ
  4751.  
  4752. Line-Acommandsare'CLIP-sensitive',soyoushouldalwaysuseanappro⑨
  4753. priateACLIP-commandbeforeaLine-Acommand.ThefollowingLine-A
  4754. commandsareênotÇinfluencedbyACLIP:ALINE,HLINE,PSET,PTSTand
  4755. BITBLT.
  4756.  
  4757.  
  4758. üBlitterÇ
  4759.  
  4760. TheBlitter-TOS(1987)allowsyoutoswitchtheBlitteron/off.Icouldn't
  4761. testthefollowingProcedure,becauseIdon'thaveaBlitter.ButifI
  4762. understandthefunctionXBIOS64(Blitmode)correctly,youcouldswitch
  4763. theBlitteronandofffromGFA-Basic:
  4764.      PROCEDUREblitter(switch!)
  4765.      LOCALstatus
  4766.      status=XBIOS(64,-1)
  4767.      IFBTST(status,1)           !Blitteravailable?
  4768.      IFswitch!
  4769.      status=BSET(status,0)   !Blitteron
  4770.      ELSE
  4771.      status=BCLR(status,0)   !Blitteroff
  4772.      ENDIF
  4773.      ~XBIOS(64,status)         !doit
  4774.      ENDIF
  4775.      RETURN
  4776.  
  4777. ÇBytheway,LineAcommandsdonotusetheBlitter.TheBlitter-chip
  4778. containsahardware-routinethatreplacestheLineABitBlt-function
  4779. (BITBLTinGFA-Basic).AllMegaST'shaveaBlitterinstalled.
  4780.  
  4781.  
  4782. üë21.EVENTS
  4783. Ç
  4784.  
  4785. üMENU()
  4786.  
  4787. ÇThereisnoeasywaytotestinaprogramifanaccessoryhasbeen
  4788. selectedbytheuser.MENU(1)lookspromising,butthevalue40(select
  4789. accessory)or41(closeaccessory)isonlysenttotheaccessory!It
  4790. wouldhavebeennicetobeabletodetermineifanaccessoryhasbeen
  4791. closed,becauseGEMwillcleartheaccessory-windowandwillfillthe
  4792. spacewiththedesktop-pattern.Noeasysolutionforthisone,sorry.The
  4793. bestideaprobablyistotestfrequentlywith'IFMENU(1)=20'ifaredraw
  4794. isnecessary,e.g.:
  4795.      ONMENUMESSAGEGOSUBredraw
  4796.      (...)
  4797.      PROCEDUREredraw
  4798.      IFMENU(1)=20
  4799.      (...)           !redrawscreen
  4800.      ENDIF
  4801.      RETURN
  4802. Thismethodonlyworksifyouhaveopenedawindow.
  4803.  
  4804.  
  4805. üONMENUBUTTONÇ
  4806.  
  4807. ThesyntaxforONMENUBUTTONis:
  4808.      ONMENUBUTTONclicks,button,eventGOSUBproc
  4809. Forboth'button'and'event'youcanusethenumbers0-3.Thevariable
  4810. 'clicks'standsfortheêmaximalÇnumberofclicksyouwanttoregister.If
  4811. youchoose'2',theProcedurewillbecallediftheuserclicksonceor
  4812. twice:
  4813.      ONMENUBUTTON2,1,1GOSUBproc
  4814. It'snotpossibletowaitforadouble-click,unlesstheprogamisreally
  4815. waiting,andnotdoinganythingelse:
  4816.      SELECTEVNT_BUTTON(2,1,1)
  4817.      CASE1
  4818.      'clickedonce
  4819.      CASE2
  4820.      'clickedtwice
  4821.      ENDSELECT
  4822. Butyoucan'tcombinethiswithanONMENUloop.
  4823.  
  4824. Ifyouusethedescribedmethod:
  4825.      ONMENUBUTTON2,1,1GOSUBproc
  4826. youcoulduseMENU(15)inthecalledProceduretocheckiftheuser
  4827. clickedtwice.ThesameProcedurewouldbecalledafterasingleclick,
  4828. butyoucouldignorethat.Fastenyourseatbeltsnow.Ifyourunsucha
  4829. programthefirsttime,adoubleclickisênotÇregisteredinMENU(15).If
  4830. yoususpectabugandruntheprogramagain,MENU(15)worksallright.
  4831. Nasty.
  4832.  
  4833. ÇAnotherbug,butthistimeaGEM-bug(Ithink),after:
  4834.      ONMENUBUTTON1,2,2GOSUBproc
  4835. TheProcedureiscalledimmediately,whethertherightmouse-buttonwas
  4836. pressedornot.
  4837.  
  4838. IfyouwanttoswitchONMENUBUTTONtemporarilyoff,use:
  4839.      ONMENUBUTTONclicks,button,eventGOSUBdummy
  4840. TheProcedureDummyshouldbeempty.Usethesamemethodtoswitchother
  4841. ONMENUcommandstemporarilyoff.
  4842.  
  4843.  
  4844. üONMENUIBOXÇ
  4845.  
  4846. YoucandefinetwoindependentrectangleswithONMENUIBOXand/orONMENU
  4847. OBOX,either:
  4848.      -oneIBOXandoneOBOX
  4849.      -twoIBOXes
  4850.      -twoOBOXes
  4851.  
  4852.  
  4853. üë22.PULLDOWNMENU
  4854. Ç
  4855.  
  4856. üOPENW0Ç
  4857.  
  4858. Evenifyoudon'tneedawindow,youcould'OPENW0'ifyouusea
  4859. pulldownmenu.Thetopline(y-coordinates0to18inHighresolution,
  4860. that'swhereyourmenuis)isnowprotectedagainstaccidentaldrawing.
  4861. After'OPENW0'19isalwaysaddedtothey-coordinate,sowith'PLOT0,0'
  4862. thepointisactuallydrawnat(0,19).
  4863.  
  4864.  
  4865. üDesk-submenuÇ
  4866.  
  4867. TheêfirstÇsubmenuinapulldownmenushouldbetheDesk-submenu('Desk'),
  4868. usuallywiththefollowinglay-out:
  4869.      Info
  4870.      ------------
  4871.      Accessory1
  4872.      Accessory2
  4873.      (...)
  4874. IftheuserchoosestheInfo-item,youshouldshowsomeinformationabout
  4875. theprogram.TheAEStakescareoftheaccessory-items,yousimplyuse
  4876. '1,2,3,4,5,6'inthecorrespondingDATA-line.Ifyouuse'-,-,-,-,-,-'the
  4877. userwon'tbeabletochooseanaccessoryfromyourprogram,butall
  4878. loadedaccessoriesstilloccupymemory.
  4879.  
  4880.  
  4881. üFile-submenuÇ
  4882.  
  4883. Mostpulldown-menu'scontainaFile-submenu('File')astheêsecondÇ
  4884. submenu.Thefollowinglay-outismoreorlessstandard:
  4885.      Newfile       ^N
  4886.      Openfile...  ^O
  4887.      -----------------
  4888.      Close          ^C
  4889.      Save           ^S
  4890.      Saveas...    ^M
  4891.      Abort          ^A
  4892.      -----------------
  4893.      Quit           ^Q
  4894. With'...'youannouncethatfurtherinputfromtheuserwillbe
  4895. requested.Ifatallpossible,youshouldofferoptionalkeyboard-
  4896. alternativesfortheexperienceduser.With'^N'youremindtheuserof
  4897. the<Control><N>alternative.ThecharacterwithASCII-code7isusedas
  4898. thesymbolfor<Alternate>.Bygeneralagreement,theQuit-choicealways
  4899. isthelastitemoftheFile-submenu.
  4900.  
  4901. Bytheway,neverleavethelast(rightmost)submenuwithoutoptions,e.g.
  4902. duringdevelopmentofaprogram.Theremustbeatleastoneoptioninthe
  4903. lastsubmenu,orit'sreset-timeagain.
  4904.  
  4905.  
  4906. üë23.WINDOWS
  4907. ê
  4908.  
  4909. üGFA-windowsÇ
  4910.  
  4911. You'llnoticethatthischapterisrathershort.Thisreflectsmy
  4912. reservationsabouttheuseofwindows.Iknowveryfewprogramsthatuse
  4913. windowssensibly.FortheseprogramsGEM-windowsindeedareablessing.
  4914. Butmostprogramsarebetteroffwithoutwindows.GEMjustslowsthe
  4915. screen-outputdown.CoveryourTOS-screenwithwindowsonlyifyoureally
  4916. needthem.
  4917.  
  4918. GFA-Basichasfour"easy"windowsfornottoocomplicatedjobs.Drawan
  4919. imaginarycrossonthescreen.Theintersectionofthetwolinesis
  4920. determinedbythecoordinatesin'OPENWn,x,y'.Ifyoushowmorethanone
  4921. windowonthescreen,youshouldrealizethatresizingonewindowauto-
  4922. maticallychangesthesizeoftheotherthreewindowsaswell(remember
  4923. thecross?).UsetheAESwindow-commandsifyouneedindependentwindows.
  4924.  
  4925. ThefourGFA-windowsreservethetoplineforapulldownmenu.Ifyouuse
  4926. yourownAES-windows,youshouldprotectthetoplineyourself,e.g.with
  4927. 'OPENW0'.
  4928.  
  4929. Astandard-methodfortheuseofGFA-windowslookslikethis:
  4930.      TITLEW#1,"title"      !automaticallycentered
  4931.      INFOW#1,"information"   !leftjustified
  4932.      OPENW1                  !oruseFULLW#1
  4933.      CLEARW1
  4934.      (...)
  4935.      CLOSEW1
  4936.      CLOSEW0
  4937. Idon'tknowhowtouse'#'properly.Theeditordoesnotaccept'#'in
  4938. 'OPEN#1',youhavetouse'OPENW1'.IfyouuseFULLWinsteadofOPENW,
  4939. youhavetouse'FULLW#1'.Inthiscasethe'#'hastobeused,orthe
  4940. commanddoesn'tworkatall!TheGFA-editoralwaysinsertsa'#'after
  4941. TITLEWandINFOW,evenifyoudidn'ttypeone.Whatthe#isgoingon?
  4942.  
  4943. ü
  4944. CLOSEWÇ
  4945.  
  4946. Ifyouhaveopenedawindowinyourprogram,alwaysuse'CLOSEW0'before
  4947. returningtotheeditor.Ifyoudon't,youcan'tworknormallyinDirect
  4948. Mode.Ifyoudidforget,youcantype'CLOSEW0'inDirectModeand
  4949. everythingworksfineagain.
  4950.  
  4951. IfyouusetheAESwindow-commands,alwayscallWIND_CLOSE(handle)before
  4952. WIND_DELETE(handle).
  4953.  
  4954.  
  4955. üTITLEWÇ
  4956. ü
  4957. ÇYoucanclearatitlewith:
  4958.      TITLEW#n,""
  4959. Don'tuse""insteadof"",oryouwon'tbeabletomovethewindow
  4960. afterwards!
  4961.  
  4962.  
  4963. üCLEARWÇ
  4964.  
  4965. After'CLEARW#n'allvisibleareasofthewindowarecleared,êwithoutÇ
  4966. activatingthewindow.GFAusesWIND_UPDATEandWIND_GETforthiscommand.
  4967. 'CLEARWn'bothclearsêandÇactivatesthewindow.
  4968.  
  4969.  
  4970. üë24.AES-LIBRARY
  4971. Ç
  4972.  
  4973. üALERTÇ
  4974.  
  4975. IfyouneedanemptylineinanAlert-box,use:
  4976.      ALERT,3,"...||...",1,"...",k
  4977. Notethespacebetweenthetwoverticalrules.
  4978.  
  4979. GFA-Basicallowsê4Çlinesof30characters(High/Mediumrez)ifyouuse
  4980. ALERT,butwithFORM_ALERTyoucanuseê5Çlines.Inbothcasesyoucanuse
  4981. notmorethan3buttons,eachatmost8characters(High/Mediumrez)wide:
  4982.      m$="line1|line2|line3|line4"
  4983.      ALERT3,m$,1,"OK",k
  4984.      '
  4985.      m$="[3][line1|line2|line3|line4|line5][OK]"
  4986.      k=FORM_ALERT(1,m$)
  4987.  
  4988. InLowresolutionyoucanuseonlyhalfthenumberofcharactersyouuse
  4989. inHigh/Mediumresolution.
  4990.  
  4991. Ifsomecharactersarenotvisibleinabutton,trybroadeningtheAlert-
  4992. boxbyaddingspacestothewidesttext-line.
  4993.  
  4994. Ifyouhavepressedtheleftmouse-buttonontheveryspotwhereanAlert-
  4995. buttonisabouttoappear,somethinggoeswrong.GEMappearstoremember
  4996. yourlastmouse-click,anderroneouslyassumesyoupressedthebutton
  4997. êafterÇtheAlert-boxappeared.GEMonlyselectsthebuttonifthemouse-
  4998. clickoccurredintheexactareaoftheAlert-button.Toavoidthis
  4999. problemyoushouldmakesuretheuserhasreleasedthemouse-buttonbefore
  5000. youcalltheAlert-box:
  5001.      REPEAT
  5002.      UNTILMOUSEK=0      !waituntilmousereleased
  5003.  
  5004. Bytheway,theAESusesan8Kbuffertosavethepartofthescreenwhere
  5005. theAlert-boxappears.Dittoforamenu.
  5006.  
  5007.  
  5008. üSHEL_GETandSHEL_PUTÇ
  5009.  
  5010. GFA-Basicisrunfroma'Shell-Program',usuallytheDesktop.Inthatcase
  5011. thefileDESKTOP.INFcanbefoundintheEnvironment-Buffer.Youcan
  5012. examinethisfilebytransferringittoastring:
  5013.      d$=STRING$(1024,0)
  5014.      r%=SHEL_GET(1024,d$)
  5015. PRINTingthisstringismucheasierthanusingadisk-editortoexamine
  5016. DESKTOP.INF.
  5017.  
  5018. ÇAfterchangingthestring,youcouldputitbackinthebufferwith:
  5019.      r%=SHEL_PUT(1024,d$)
  5020. Thiswayyoucouldchangethelay-outofthedesktop.Ifyouchangethe
  5021. string,youshouldknowthattheDesktoprecognizestheendofDESKTOP.INF
  5022. bythebyte&H1A.Sodon'tforgettoputCHR$(26)attheend.Ifyouwant
  5023. tosavethenewbuffer,try:
  5024.      OPEN"O",#1,"\DESKTOP.INF"
  5025.      PRINT#1,LEFT$(d$,INSTR(d$,CHR$(26)))
  5026.      CLOSE#1
  5027.  
  5028.  
  5029.  
  5030.  
  5031.  
  5032.  
  5033. IsthatallthereistotellabouttheAES-library?Certainlynot,soat
  5034. thispointyouwillprobablybebitterlydisappointed.IavoidtheAES-
  5035. LibrarywheneverIcan.Anyway,thisisasubjectthatisthoroughly
  5036. coveredinmostbooksaboutGFA-Basic3.0.Everyoneisentitledtohisown
  5037. opinionabouttheusefulnessofRSC-filesandotherexoticsubjects.
  5038. Betterstill,writethischapteryourself.Andthesametoyoutoo!
  5039.  
  5040.  
  5041. üë25.GFAXPERT-FILES
  5042. Ç
  5043.  
  5044. Takeyourtimetoreadthischaptercarefully,beforeusingtheGFAXPERT-
  5045. Proceduresorprograms.Theparagraph'STANxxxx.LST'isessentialreading.
  5046. Don'tforgettoreadthe'ásmallprintÇ'inthelastparagraph.
  5047.  
  5048.  
  5049. üGFAXPERT.DOCÇ
  5050.  
  5051. You'rereadingit.
  5052.  
  5053.  
  5054. üGFAXPERT.LIBÇ
  5055.  
  5056. Thisfolder(inGFAXPRT2.ARCfordownloaders)containsalargecollection
  5057. ofProceduresinseveralLST-files.EachLST-filecontainsoneormore
  5058. foldedProcedures.MostProceduresarealsolistedinthistext,orareat
  5059. leastmentioned.IsuggestyouLlistalltheLST-fileswithunfolded
  5060. Proceduresforeasyreference.YoucouldalsoLlistallLST-filesagain
  5061. withfoldedProcedures,soyouwillbeabletolocateaProcedurequickly.
  5062.  
  5063. Alwaysreadthecomment-lines('***)inaProcedurebeforeusingit.You
  5064. willfindthereifotherProceduresareused,orStandardGlobals(see
  5065. paragraph'STANxxxx.LST').SometimesaProcedurereturnsaglobal
  5066. variable.MostvariablesaredeclaredasLOCAL.Anddoreadtherelevant
  5067. chapterofthistextbeforeusingaProcedure.
  5068.  
  5069. GFAhasreleasedalibraryofgraphics-andsound-routines.Iamcurious
  5070. aboutthequalityoftheseroutines,butIcertainlydonotintendtopay
  5071. DM148.-forthelibrary.Myadvicewouldbetousethelibrary
  5072. GFAXPERT.LIBandpayDM148.-tome.
  5073.  
  5074.  
  5075. üINLINEÇ
  5076.  
  5077. TheINLINE-folder(inGFAXPRT2.ARCfordownloaders)containsINLINE-files
  5078. thatyouwillhavetoloadafterMergingcertainProcedures.Thisis
  5079. clearlyindicatedinsuchProcedures.
  5080.  
  5081.  
  5082. üSTANxxxx.LSTÇ
  5083.  
  5084. Beforewritingaprogram,Idecideinwhichresolutiontheprogramwill
  5085. run.ThenIMergethecorrespondingSTANxxx.LST-file(inthefolder
  5086. GFAXPERT.LIB)andusethatasthestandardframeworkformyprogram:
  5087.      STANHIGH.LST   -Highresolution
  5088.      STANMED.LST    -Mediumresolution
  5089.      STANLOW.LST    -Lowresolution
  5090.      STANHIME.LST   -HighorMediumresolution
  5091.      STANALL.LST    -allresolutions
  5092. Afterdeletingthefirsttwolinesandenteringthenameoftheprogram
  5093. (e.g.TEST.GFA),ISavetheprogramasAAPROG.GFAintheProcedure-
  5094. library.InthisfolderIhaveafewLST-filesreadyforeasyMergingof
  5095. ÇProceduresintotheprogram(AABLOCK1.LST,AABLOCK2.LST,etc.).
  5096.  
  5097. Beforeyoucontinue,youshouldLlistthefiveSTANxxxx.LST-files.Merge
  5098. STANHIGH.LST,unfoldallProcedures,thenLlist.Intheotherfilesyou
  5099. couldrestrictunfoldingtotheProcedureInitio(andperhapsthe
  5100. Proceduresxxx.modeandStandard.xxx.colors).I'llwaituntilyouhavethe
  5101. listingsoftheSTAN-filesinfrontofyou...
  5102.  
  5103. Right,firstI'lldiscussSTANHIGH.LSTthoroughly.LaterI'llpointout
  5104. someimportantfeaturesintheotherSTAN-files.Youwillnotbecomean
  5105. expertinstructuredprogrammingimmediately,butusingtheSTAN-files
  5106. shouldhelp.
  5107.  
  5108. (1)Thefirstline('STANHIGH.LST')istheretoremindyouhowto'Save,A'
  5109. thisfileafteryouhavechangedit.Deleteitifyouaregoingtodevelop
  5110. anewprogram.
  5111.  
  5112. (2)Enterthenameofyournewprogram(e.g.TEST.GFA)andimmediately
  5113. savetheprogramasAAPROG.GFAintheProcedure-library.
  5114.  
  5115. (3)Word-variablesaredefinedasthedefault.
  5116.  
  5117. (4)TheProcedureInitioiscalled.InthisProcedurethecurrent
  5118. resolutionischecked,andafterthat,afewimportantglobalvariables
  5119. aredefined(StandardGlobals).ThefollowingStandardGlobalsaredefined
  5120. (readthecommentsinthelistingformoreinformation):
  5121.      high.res!           scrn.col.max        return$
  5122.                          scrn.lin.max        esc$
  5123.      default.path$                           help$
  5124.                          white               undo$
  5125.      physbase%           black               
  5126.      logbase%                                interpreter$
  5127.                          on!                 run.only$
  5128.      scrn.x.max          off!                start.gfa$
  5129.      scrn.y.max                              start.prg$
  5130.                          bel$                
  5131.      char.width                              
  5132.      char.height                             
  5133. Also,theStandardArraycolor.index()iscreated,althoughyou'llonly
  5134. needitforafewProcedures(e.g.Initio.sprite1).
  5135.  
  5136. (5)TheProcedureTitle.screenisnotactivatedyet.You'llprobablywant
  5137. tochangethatProcedure.
  5138.  
  5139. (6)Anormal<Break>shouldbepossiblewhiledevelopingaprogram.Inthe
  5140. finishedprogramyoucouldactivatetheProcedureBreak,ordeleteit.Be
  5141. verycarefulwith<Break>iftheprogramusesRESERVEorhaschangedthe
  5142. addressofthephysical/logicalscreen.
  5143.  
  5144. (7)ThemainprogramusuallyisnotmuchmorethanalistofProcedure-
  5145. calls,e.g.:
  5146.      @start.game
  5147.      @play.game
  5148.      @score
  5149. Ç(8)TrytoleavetheprogrambycallingtheProcedureExit.During
  5150. developmentit'smoreconvenienttoleavewith'EDIT'.
  5151.  
  5152. (9)TwoStandardFunctionsaredefined:Center$forcenteringtextand
  5153. Rev$forPRINTingreverse.ThelastfunctionusesVT52-codes,souseiton
  5154. theTOS-screenonly.
  5155.  
  5156. (10)TheStandardProcedureHigh.mode(calledfromInitio)checksthe
  5157. currentresolutionandabortswithanappropriatemessageiftheprogram
  5158. isruninthewrongresolution.
  5159.  
  5160. (11)TheStandardProcedureGet.path(calledfromInitio)returnsthe
  5161. currentpath.Usingtheinterpreter,GEMDOSreturnsthepathofthe
  5162. interpreter(e.g.'A:\'),ênotÇoftherunningprogram!That'swhyIuse
  5163. CHDRIVE+CHDIRintheshell-programs.InthatcasetheStandardGlobal
  5164. default.path$doescontainthepathoftherunningGFA-program.Ifyou
  5165. developtheprogram,youshoulduseCHDRIVE/CHDIRinDirectModeif
  5166. necessary.Iamnothappywiththismethod,butIknownoothersolution
  5167. forGFA-programs.IfIdon'tusethismethod,Ialwaysdefinethepathin
  5168. theInitiation-part,e.g.:
  5169.      path$="A:\GAMES\"        !wherearethedata-files?
  5170. NowanotherGFA-useronlyhastochangethepathandtheprogramcanfind
  5171. thenecessaryfiles.ForownersoftheRun-Onlyinterpreteryoushould
  5172. describetheproperconfigurationinaREAD.ME-file.WithcompiledGFA-
  5173. programsthereisnoproblem,becauseGEMDOSwillreturnthepathofthe
  5174. runningprogram.
  5175.  
  5176. (12)Iliketobegineveryprogramwithatitle-screen.Changethe
  5177. StandardProcedureTitle.screen,ordeleteitifyoudon'tliketitle-
  5178. screensinyourprograms.
  5179.  
  5180. (13)TheStandardProcedureReturnisusedbyTitle.screen.
  5181.  
  5182. (14)TheStandardProcedureBreakcanbedeletedifyoudon'tneedit.
  5183. Don'tuse'ONBREAKCONT'inyourprogram,unlessyouhaveaverygood
  5184. reasontodoso.NotethatIhavemadeitpossibletouse<Break>the
  5185. normalwayiftheuserchooses<CONT>whilepressingthe<Break>-
  5186. combination.
  5187.  
  5188. (15)TheStandardProcedureExitshouldalwaysbeused.ThisProcedure
  5189. triestogobacktooneoftheshell-programs.Ifthat'simpossible,the
  5190. Proceduredecidestoendwith'EDIT'or'SYSTEM'.Isitpossibletotest
  5191. inaprogramifitisrunbytheinterpreterorifitisacompiled
  5192. program?Iftheanswerisyes,thisProcedurecouldbeimproved.
  5193.  
  5194. (16)OtherProcedurescanbeinsertedafter'***Procedures***'.Merge
  5195. ProceduresfromthelibraryGFAXPERT.LIB(oryourownlibrary)here.Iuse
  5196. thefollowingmethod:
  5197.      -New,somemoryisclear
  5198.      -MergerelevantLST-filefromlibrary
  5199.      -choose(folded)ProcedureandWriteasblocktoAABLOCKx.LST
  5200.      -repeatpreviousstepsforotherProcedure(s)
  5201.      -LoadAAPROG.GFA
  5202.      -MergeAABLOCKx.LSTatappropriateposition(s)
  5203. Ç     -Saveprogram(press<Return>inFileselector)
  5204. Ofcourse,you'llhavetowriteafewProceduresfromscratch.Beforeyou
  5205. knowit,you'llhavereachedTheEnd.It'ssoeasytowriteaprogramin
  5206. GFA-Basic3.0,thatIactuallyenjoyprogramming.
  5207.  
  5208. (17)Debuggingisperhapslessfunthanprogramming.MergetheProcedure
  5209. Debugtemporarilyinyourprogramifyouneedsomehelp.Anddosaveyour
  5210. programregularly!FallbacktotheprogramAAPROG.BAKifyourlatest
  5211. improvementswerefatal.Ifyouarecompletelysatisfied,savetheprogram
  5212. underitspropername(TEST.GFA).Alsosaveaback-uponanotherdisk,
  5213. justincasesomethingterribleshouldhappentoyouroriginalprogram.
  5214.  
  5215. (18)InSTANALL.LSTyou'llnoticeintheProcedureInitiothatIalways
  5216. startwiththedefaultpalette(ProceduresStandard.med.colorsand
  5217. Standard.low.colors).NewStandardGlobalsinSTANALL.LSTare:
  5218.      red            med.res!
  5219.      green          low.res!
  5220. TheStandardArraycolor.index()isveryimportantinMediumorLow
  5221. resolution.
  5222.  
  5223. (19)InSTANHIME.LST(myfavourite)theonlyimportantdifferenceisthe
  5224. ProcedureHigh.med.mode,wherethecurrentresolutionischecked.
  5225.  
  5226. (20)InSTANLOW.LSTall16default-coloursarenowdefinedasStandard
  5227. Globals :
  5228.      white          blue           grey           l.purple
  5229.      black          d.blue         l.black        d.purple
  5230.      red            brown          l.blue         d.yellow
  5231.      green          d.green        bluegreen      l.yellow
  5232. WithtwonewStandardFunctionsyoucanchangethecolourofPRINTedtext
  5233. (Ink$)orthecolourofthebackground(Paper$).Bothfunctionsworkon
  5234. theTOS-screenonly.ThecurrentresolutionischeckedintheProcedure
  5235. Low.mode.
  5236.  
  5237. (21)NothingnewinSTANMED.LST,excepttheProcedureMed.modetocheck
  5238. theresolution.
  5239.  
  5240. Perhapsyoufindallthistalkabouta"standard"program-structurevery
  5241. boring.Ifyouwriteaprogram,whycareaboutstructure?Becauseit's
  5242. mucheasiertochangeastructuredprogram,especiallyifyoudidn'twrite
  5243. theprogramyourself.Changeanunstructuredprogram,andyou'regoingto
  5244. besurprisedbysome(hidden)unwantedside-effects.Makeotherusers
  5245. happy,spreadyourbeautifulprogramsonlyiftheyarestructuredandwell
  5246. commented.Dospreadthe(listable)êsourceÇofyourprogram,sootherusers
  5247. canlearnfromyou.Anddon'tbeinsultedifothersimproveyourprogram.
  5248. Icertainlywillnotbeinsultedifyousendmeyourownthoughtsabout
  5249. structuredprogramminginGFA-Basic3.0.
  5250.  
  5251.  
  5252.  
  5253. üSTART
  5254. Ç
  5255. IntheSTART-folder(inGFAXPRT2.ARCfordownloaders)youwillfindthe
  5256. followingprograms:
  5257.      START.GFA      -HighorMediumresolution
  5258.      STARTLOW.GFA   -Lowresolution
  5259.      GFASTART.GFA   -allresolutions
  5260.  
  5261. IusetwodifferentdisksformyGFA-programs.Oneforprogramsthatrun
  5262. inHighand/orMediumresolution(savethedesktopinMediumresolution!).
  5263. AndoneforprogramsthatruninLowresolution.
  5264.  
  5265. START.GFAandSTARTLOW.GFAareusedasakindofshelltoruntheGFA-
  5266. programsonthesedisks.Notatrueshell,butit"feels"likeallGFA-
  5267. programsarerunfromSTART.GFAandSTARTLOW.GFA.IstartaGFA-session
  5268. bydouble-clickingtheshell-programonthedesktop('GFA'hasbeen
  5269. installedasapplicationforGFABASIC.PRG).
  5270.  
  5271. AllmyprogramstrytoCHAINoneoftheshell-programswhentheuserexits
  5272. theprogram.Twoimportantremarksifyoudecidetousetheseshell-
  5273. programs:
  5274.      -verticalfrequencyisswitchedto60HzinMediumorLowresolu⑨
  5275.      tion;notagoodideaifyouuseaTVthroughamodulator!
  5276.      -WriteVerifyTestisswitchedoff
  5277. Ifyoulike,youcanactivatethecheckforaboot-virusintheshell-
  5278. programs.Theshell-programandGFABASIC.PRG(orGFABASRO.PRG)shouldbe
  5279. inthemaindirectory!
  5280.  
  5281. GFASTART.PRGisusedinthesamewaywithcompiledGFA-programs.Allmy
  5282. compiledGFA-programstrytoCHAINthisshell-programwhenexiting.The
  5283. sourceforthisprogramisGFASTART.GFA.CompilethisasGFASTART.PRGand
  5284. putitinthemaindirectory.
  5285.  
  5286. AllthreeSTART-programscontainplentycomments,soyoushouldbeableto
  5287. understandhowtheprogramsworkbystudyingthelistings.Theshell-
  5288. programscertainlycanbeimproved,I'mnotyetsatisfiedwiththecurrent
  5289. programs.
  5290.  
  5291.  
  5292. ísmallprintÇ
  5293.  
  5294. Readthisparagraphcarefully,beforeusingtheGFAXPERT-files.Thefiles
  5295. areênotÇPublicDomain!
  5296.  
  5297. YouarefreetouseandchangeallGFAXPERT-files,butonlyforpersonal
  5298. use.Certainlynotforcommercialuse.
  5299.  
  5300. YouareinvitedtocopytheoriginalGFAXPERT-diskortheGFAXPRTx.ARC-
  5301. filesandgivethesetoyourfriends.Butyouarenotallowedtochange
  5302. anythingonthediskorinthefiles.Ifyoufeeltheurgetochange
  5303. something,don'tdoit,butwritetome(readthechapter'EPILOGUE').
  5304.  
  5305. Youarenotallowedtosell(filesfrom)theGFAXPERT-diskoroneofthe
  5306. GFAXPRTx.ARC-files.ThediskGFAXPERTmayonlybesoldbyso-calledPublic
  5307. DomainClubsiftheyhavemywrittenpermissiontodoso.BBS'sarefree
  5308. tomaketheoriginalGFAXPRTx.ARC-filesavailablefordownloading.
  5309.  
  5310. AnypartfromthetextGFAXPERT.DOCortheProcedure-libraryGFAXPERT.LIB
  5311. maybequotedinnewslettersormagazines,ifaccompaniedbyareference
  5312. like:
  5313.      fromGFAXPERT(2nded.)byHanKempen
  5314.  
  5315. Icannotbeheldresponsibleforanydamagethatmayresultfromrunninga
  5316. GFAXPERT-program,usingaProcedurefromthelibraryGFAXPERT.LIB,or
  5317. usinginformationfromthistext.
  5318.  
  5319.  
  5320. (c)HanKempen,3July1990
  5321.  
  5322.  
  5323. üëEPILOGUE
  5324. Ç
  5325.  
  5326. Well,that'sallfolks.I'mquitecertaintherearestillafewbugstobe
  5327. foundinthistextandintheProcedure-LibraryGFAXPERT.LIB.Bynowyou
  5328. shouldhavebecomeanexpertinGFA-Basic3.0,soyouwillbeabletospot
  5329. thembugsimmediately.Pleaseletmeknowifyoufindone.
  5330.  
  5331. PerhapsyoustillhavesomeunansweredquestionsaboutGFA-Basic.Oran
  5332. answertooneofmyownquestionsinthistext.OrsomeneatProcedures.
  5333. Orabrilliantprogram.Iwouldappreciateitverymuchifyouwouldsend
  5334. yourletterand/ordiskto:
  5335.  
  5336.      HanKempen
  5337.      Rubensstraat12
  5338.      7741ARCoevorden
  5339.      theNetherlands
  5340.  
  5341. Doshareyourideas,Proceduresandprogramswithothers,startingwith
  5342. me.ConsideritasmallpaymentfortheGFAXPERT-files.Thanks.
  5343.  
  5344.  
  5345.  
  5346.  
  5347.  
  5348.  
  5349. WishingyoumanyhappyhourswithGFA-Basic3.0,
  5350.  
  5351.  
  5352. HanKempen
  5353.  
  5354.  
  5355. üëINDEX
  5356. Ç
  5357.  
  5358.  
  5359. (#) = Procedure or Function
  5360.  
  5361.  
  5362. \ .....................................  29
  5363. " .....................................  41
  5364. 1st Word Plus .........................  62
  5365. 40-folder limit .......................  66
  5366.  
  5367. abbreviated commands ..................  12
  5368. accessory .............................  25,101
  5369. ACHAR .................................  96
  5370. ACLIP .................................  99
  5371. After$ (#) ............................  32
  5372. AFTER .................................  82
  5373. ALERT ................................. 106
  5374. application ...........................   9
  5375. ARECT .................................  88
  5376. ASCII-code ............................  33,34,36,37
  5377. Ascii.qsort (#) .......................  27
  5378. ATEXT .................................  96
  5379. attribute .............................  53
  5380. AUTO ..................................   9
  5381.  
  5382. BCHG ..................................  30
  5383. BCLR ..................................  29
  5384. Before$ (#) ...........................  32
  5385. Bezier-curve ..........................  92
  5386. BGET ..................................  62
  5387. BIOS  4 (Rwabs) .......................  59
  5388. BIOS  7 (Getbpb) ......................  56,60
  5389. BIOS  9 (Mediach) .....................  60
  5390. BIOS 10 (Drvmap) ......................  51
  5391. BIOS 11 (Kbshift) .....................  36
  5392. bit-mask ..............................  29
  5393. Blitter (#) ...........................  99
  5394. BLOAD .................................  61
  5395. Block.dimmer (#) ......................  91
  5396. Boolean ...............................  17
  5397. boot ..................................   9,61
  5398. BPB ...................................  56
  5399. BPUT ..................................  62
  5400. break .................................  10
  5401. Break (#) ............................. 110
  5402. BSAVE .................................  61
  5403. BSET ..................................  30,79
  5404. bug (GFA) .............................  12,20,24,25,31,32,36,42,80,83,
  5405.                                                         84,92,96,97,101
  5406. bug (TOS) .............................  25,35,55,56,63,64,66,70,95,102
  5407.  
  5408. Çcalculations ..........................  79
  5409. Caps (#) ..............................  39
  5410. CapsLock ..............................  38
  5411. CARD ..................................  31
  5412. CHAIN .................................  83
  5413. Change.font (#) .......................  44
  5414. Change.midi.buffer (#) ................  67
  5415. Change.palette (#) ....................  85
  5416. characters ............................  16,34
  5417. CHDIR .................................  51,110
  5418. CLEAR .................................  19
  5419. CLEARW ................................ 105
  5420. CLIP ..................................  92
  5421. CLOSEW ................................ 104
  5422. cluster ...............................  58
  5423. Coldstart (#) .........................   9
  5424. color .................................  40
  5425. Color.cycle (#) .......................  86
  5426. correlation ...........................  31
  5427. COSQ ..................................  30
  5428. CURVE .................................  92
  5429. Cut and Paste .........................  13
  5430. Cycle.once (#) ........................  87
  5431.  
  5432. DATE$ .................................  22
  5433. Day.of.week (#) .......................  22
  5434. Debug (#) .............................  19,111
  5435. DEFFILL ...............................  87
  5436. DEFLINE ...............................  89
  5437. DEFLIST ...............................  15
  5438. DEFMARK ...............................  87
  5439. DEFMOUSE ..............................  72
  5440. DEFTEXT ...............................  89
  5441. DEFWRD ................................  17
  5442. Degas-Pictures ........................  97
  5443. Degas.screendump (#) ..................  46
  5444. DELAY .................................  83
  5445. Desk-submenu .......................... 103
  5446. DESKTOP.INF ........................... 106
  5447. DFREE .................................  56,58
  5448. Digital$ (#) ..........................  93
  5449. DIM ...................................  19
  5450. Dim.colors (#) ........................  86
  5451. DIR$() ................................  50
  5452. DIR ...................................  51
  5453. Direct mode ...........................  15
  5454. disk format ...........................  55
  5455. disk-swap .............................  60
  5456. Do.sound (#) ..........................  76
  5457. DRAW ..................................  91
  5458. DTA-buffer ............................  52
  5459. DUMP ..................................  19
  5460.  
  5461. ÇEditor ................................  71
  5462. EQV ...................................  31
  5463. ERASE .................................  19,24
  5464. ERROR .................................  82
  5465. EVERY .................................  82
  5466. EXEC ..................................  24,83
  5467. EXIST .................................  54
  5468. Exit (#) .............................. 110
  5469.  
  5470. fade-over .............................  99
  5471. Fastprint (#) .........................  41
  5472. FAT ...................................  58
  5473. FDC ...................................  55
  5474. FGETDTA ...............................  52
  5475. File Allocation Table .................  58
  5476. File.copy (#) .........................  55
  5477. File-submenu .......................... 103
  5478. FILES .................................  51
  5479. FILESELECT ............................  63
  5480. Fileselect (#) ........................  64
  5481. Fileselector ..........................  63,71
  5482. floating point ........................  18
  5483. Floppy Write Test .....................  50
  5484. Folded Procedures .....................  13
  5485. font ..................................  43,89
  5486. Font.8x16 (#) .........................  43
  5487. Font.8x8 (#) ..........................  43
  5488. FONTKIT ...............................  44
  5489. FOR ... NEXT ..........................  79
  5490. Force.mediach (#) .....................  60
  5491. FORM_ALERT ............................ 106
  5492. FSETDTA ...............................  52
  5493. FSFIRST ...............................  52
  5494. FSNEXT ................................  52
  5495. Full.fill (#) .........................  88
  5496. FULLW ................................. 104
  5497. FUNCTION ..............................  19
  5498.  
  5499. GEMDOS 17 (Cprnos) ....................  45
  5500. GEMDOS 25 (Dgetdrv) ...................  50
  5501. GEMDOS 48 (Sversion) ..................  10
  5502. GEMDOS 54 (Dfree) .....................  56
  5503. GEMDOS 67 (Fattrb) ....................  53
  5504. GET ...................................  96
  5505. Get.path (#) .......................... 110
  5506. GFA-windows ........................... 104
  5507. GFAXPERT.DOC ..........................   7,108
  5508. GFAXPERT.LIB ..........................   7,108
  5509. GOSUB .................................  82
  5510. GOTO ..................................  82
  5511. GRAPHMODE .............................  90
  5512.  
  5513. ÇHARDCOPY ..............................  45
  5514. harddisk ..............................  51,55,58,59
  5515. High.screendump.epson (#) .............  45
  5516. High.screendump.star24 (#) ............  45
  5517. HLINE .................................  96
  5518.  
  5519. IBOX .................................. 102
  5520. IF ... ENDIF ..........................  78
  5521. INFOW ................................. 194
  5522. Initio (#) ............................ 109
  5523. Initio.fill1 (#) ......................  88
  5524. Initio.high.fill1 (#) .................  87
  5525. Initio.keyget (#) .....................  36
  5526. Initio.logical.screen (#) .............  42
  5527. Initio.mouse1 (#) .....................  72
  5528. Initio.printer (#) ....................  47
  5529. Initio.sound (#) ......................  75
  5530. Initio.sprite1 (#) ....................  93
  5531. Initio.text.array (#) .................  62
  5532. Ink$ (#) ..............................  40
  5533. INKEY$ ................................  33
  5534. INLINE ................................  24,108
  5535. INP ...................................  62,67,70
  5536. INPAUX$ ...............................  70
  5537. INPMID$ ...............................  67
  5538. INPUT .................................  34,62
  5539. INPUT$ ................................  35
  5540. Insert-mode ...........................  15
  5541. INSTR .................................  32
  5542. INT{} .................................  23
  5543. integer ...............................  18
  5544. Intel.word (#) ........................  31
  5545. interleave ............................  57
  5546. Invert.block (#) ......................  91
  5547.  
  5548. joystick ..............................  74
  5549.  
  5550. Key.click (#) .........................  38
  5551. Key.repeat (#) ........................  39
  5552. keyboard ..............................  37
  5553. keyboard-buffer .......................  33
  5554. Keyboard.version (#) ..................  37
  5555. KEYDEF ................................  37
  5556. KEYGET ................................  35
  5557. KEYLOOK ...............................  36
  5558. KEYPAD ................................  37
  5559. KEYPRESS ..............................  37
  5560. KEYTEST ...............................  35
  5561. KILL ..................................  54
  5562.  
  5563. ÇLine-A ................................  95
  5564. LINE INPUT ............................  35,62
  5565. Llist .................................  14
  5566. Load ..................................  13
  5567. LOCATE ................................  41
  5568. LOF ...................................  54
  5569. LOG ...................................  30
  5570. logical screen ........................  42
  5571. loops .................................  80,119
  5572. LSET ..................................  32
  5573.  
  5574. Make.high.fill (#) ....................  88
  5575. Make.mouse (#) ........................  73
  5576. Make.palette.string (#) ...............  85
  5577. Make.sprite (#) .......................  94
  5578. MALLOC ................................  25
  5579. MAX ...................................  31,78
  5580. Max.array (#) .........................  31
  5581. memory ................................  23,24,25
  5582. MENU() ................................ 101
  5583. Midi-buffer ...........................  67
  5584. Midi-commands .........................  67
  5585. Midi.monitor (#) ......................  68
  5586. MIN ...................................  78
  5587. MOD ...................................  29
  5588. monitor ...............................  10
  5589. MOUSE .................................  71
  5590. MS-DOS disk ...........................  58
  5591.  
  5592. NAME ..................................  54
  5593. Neochrome-Pictures ....................  98
  5594. New.med.colors (#) ....................  85
  5595. Normal.font (#) .......................  44
  5596. NOT ...................................  81
  5597.  
  5598. OBOX .................................. 102
  5599. ON BREAK GOSUB ........................  82
  5600. ON MENU BUTTON ........................ 101
  5601. ON MENU IBOX .......................... 102 
  5602. OPENW ................................. 104
  5603. OPENW 0 ............................... 103
  5604. Operating System ......................  10
  5605. OUT ...................................  40,62
  5606. Overwrite-mode ........................  15
  5607.  
  5608. palette ...............................  84,111
  5609. Palette.box (#) .......................  86
  5610. Paper$ (#) ............................  40
  5611. Parse.filename (#) ....................  65
  5612. parser ................................  32
  5613. PCIRCLE ...............................  92
  5614. physical screen .......................  42
  5615. ÇPlay.midi (#) .........................  68
  5616. PLOT ..................................  91
  5617. point-commands ........................  14
  5618. PRED ..................................  29
  5619. PRINT .................................  40
  5620. Print.stopwatch (#) ...................  21
  5621. PRINT TAB .............................  42
  5622. printer-commands ......................  47
  5623. printer-driver ........................  14
  5624. printer-parameters ....................  45
  5625. Printer.ready (#) .....................  45
  5626. PUT ...................................  96
  5627.  
  5628. QSORT .................................  26
  5629.  
  5630. RAM ...................................  23
  5631. RAM-disk ..............................  50
  5632. READ ..................................  20
  5633. RECALL ................................  62
  5634. Record.midi (#) .......................  67
  5635. RESERVE ...............................  23
  5636. reset .................................   9,50
  5637. RESTORE ...............................  20
  5638. Restore.palette (#) ...................  85
  5639. Restore.physical.screen (#) ...........  43
  5640. Return (#) ............................ 110
  5641. reverse ...............................  41,84
  5642. Rgb.value (#) .........................  85
  5643. right justification ...................  32
  5644. RS232-buffer ..........................  70
  5645. RSET ..................................  32
  5646. Rubber.line (#) .......................  90
  5647.  
  5648. samples ...............................  76
  5649. Save ..................................  14
  5650. Save,A ................................  14
  5651. Save.palette (#) ......................  85
  5652. scan-code .............................  33,36,37,38
  5653. scrap-library .........................  83
  5654. Screen.dimmer (#) .....................  91
  5655. Screendump (#) ........................  45
  5656. Scroll.text.up (#) ....................  99
  5657. Scroll.up (#) .........................  98
  5658. sectors ...............................  59
  5659. SELECT ................................  78
  5660. serial number .........................  57
  5661. SETCOLOR ..............................  84
  5662. SETMOUSE ..............................  71
  5663. SHEL_GET .............................. 106
  5664. SHEL_PUT .............................. 106
  5665. shell-program ......................... 112
  5666. SHL ...................................  79
  5667. Show.degas (#) ........................  97
  5668. Show.text.page (#) ....................  63
  5669. ÇShuffle (#) ...........................  20
  5670. SINQ ..................................  30
  5671. SOUND .................................  75
  5672. Soundmachine ..........................  77
  5673. special characters ....................  16
  5674. speech ................................  77
  5675. SPRITE ................................  93
  5676. SSORT .................................  26
  5677. Standard ..............................   7
  5678. Standard Array ........................ 109,111
  5679. Standard Functions .................... 110,111
  5680. Standard Globals ...................... 109,111
  5681. STANxxxx.LST .......................... 108
  5682. START ................................. 112
  5683. start-up ..............................   9
  5684. Step Rate .............................  50
  5685. STICK .................................  74
  5686. Stopwatch (#) .........................  21
  5687. STORE .................................  62
  5688. STRIG .................................  74
  5689. String.index.qsort (#) ................  28
  5690. SUCC ..................................  29
  5691. supervisor mode .......................  23
  5692. SWAP ..................................  20,31
  5693. Swap.screen (#) .......................  43
  5694. syntax ................................  12
  5695. system-font ...........................  43,89
  5696.  
  5697. Tab ...................................  13,41
  5698. TAB ...................................  42
  5699. TEXT ..................................  92
  5700. text-array ............................  62
  5701. Text.at (#) ...........................  92
  5702. TIME$ .................................  21
  5703. Time (#) ..............................  21
  5704. TIMER .................................  21
  5705. Title.screen (#) ...................... 110
  5706. TITLEW ................................ 104,105
  5707. TOS ...................................  10
  5708. TOS-screen ............................  40
  5709. TOUCH .................................  54
  5710. twisted format ........................  57
  5711. TYPE ..................................  20
  5712.  
  5713. VAR ...................................  18
  5714. variable type .........................  17
  5715. VDISYS 38 (vqt_attributes) ............  89
  5716. VQT_EXTENT ............................  95
  5717. VSETCOLOR .............................  84
  5718. VSYNC .................................  98
  5719. VT52 ..................................  40
  5720.  
  5721. ÇWarmstart (#) .........................   9
  5722. WAVE ..................................  75
  5723. WIND_CLOSE ............................ 104
  5724. word ..................................  17,31 
  5725. WORD ..................................  23,59
  5726. write-protect .........................  60
  5727.  
  5728. XBIOS  0 (Initmous) ...................  71
  5729. XBIOS  5 (Setscreen) ..................  42
  5730. XBIOS  6 (Setpalette) .................  85,97
  5731. XBIOS  7 (Setcolor) ...................  84
  5732. XBIOS  8 (Floprd) .....................  60
  5733. XBIOS 10 (Flopfmt) ....................  56
  5734. XBIOS 15 (Rsconf) .....................  70
  5735. XBIOS 16 (Keytbl) .....................  37,38
  5736. XBIOS 18 (Protobt) ....................  57
  5737. XBIOS 19 (Flopver) ....................  56
  5738. XBIOS 32 (Dosound) ....................  75
  5739. XBIOS 33 (Setprt) .....................  45
  5740. XBIOS 36 (Prtblk) .....................  47
  5741. XBIOS 64 (Blitmode) ...................  99
  5742.  
  5743.